Cataclysm BN
item Class Reference

#include <item.h>

Inheritance diagram for item:
visitable< item >

Classes

class  craft_data
 Data for items that represent in-progress crafts. More...
 
struct  default_charges_tag
 Suppress randomization and always start with default quantity of charges. More...
 
struct  solitary_tag
 Default (or randomized) charges except if counted by charges then only one charge. More...
 
struct  sound_data
 

Public Types

using FlagsSetType = cata::flat_set< std::string >
 
using archive_type_tag = io::object_archive_tag
 

Public Member Functions

 item ()
 
 item (item &&)
 
 item (const item &)
 
itemoperator= (item &&)
 
itemoperator= (const item &)
 
 item (const itype_id &id, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype *type, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype_id &id, time_point turn, default_charges_tag)
 
 item (const itype *type, time_point turn, default_charges_tag)
 
 item (const itype_id &id, time_point turn, solitary_tag)
 
 item (const itype *type, time_point turn, solitary_tag)
 
 item (const recipe *rec, int qty, std::list< item > items, std::vector< item_comp > selections)
 For constructing in-progress crafts. More...
 
template<typename... Args>
 item (const std::string &itype, Args &&... args)
 
 ~item ()
 
safe_reference< itemget_safe_reference ()
 Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to. More...
 
itemconvert (const itype_id &new_type)
 Filter converting this instance to another type preserving all other aspects. More...
 
itemdeactivate (const Character *ch=nullptr, bool alert=true)
 Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op. More...
 
itemactivate ()
 Filter converting instance to active state. More...
 
units::energy mod_energy (const units::energy &qty)
 Add or remove energy from a battery. More...
 
itemammo_set (const itype_id &ammo, int qty=-1)
 Filter setting the ammo for this instance Any existing ammo is removed. More...
 
itemammo_unset ()
 Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present. More...
 
itemset_damage (int qty)
 Filter setting damage constrained by min_damage and max_damage. More...
 
item split (int qty)
 Splits a count-by-charges item always leaving source item with minimum of 1 charge. More...
 
const mtypeget_mtype () const
 
void set_mtype (const mtype *m)
 Sets the monster type associated with this item (corpse). More...
 
bool is_corpse () const
 Whether this is a corpse item. More...
 
bool can_revive () const
 Whether this is a corpse that can be revived. More...
 
bool ready_to_revive (const tripoint &pos) const
 Whether this corpse should revive now. More...
 
bool is_money () const
 
nc_color color () const
 Returns the default color of the item (e.g. More...
 
nc_color color_in_inventory () const
 Returns the color of the item depending on usefulness for the player character, e.g. More...
 
nc_color color_in_inventory (const player &p) const
 Returns the color of the item depending on usefulness for the passed player, e.g. More...
 
std::string tname (unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
 Return the (translated) item name. More...
 
std::string display_money (unsigned int quantity, unsigned int total, const std::optional< unsigned int > &selected=std::nullopt) const
 
std::string display_name (unsigned int quantity=1) const
 Returns the item name and the charges or contained charges (if the item can have charges at all). More...
 
std::vector< iteminfoinfo () const
 Return all the information about the item and its type as a vector. More...
 
std::vector< iteminfoinfo (int batch) const
 
std::vector< iteminfoinfo (const iteminfo_query &parts, int batch, temperature_flag temperature) const
 
std::vector< iteminfoinfo (temperature_flag temperature) const
 
std::string info_string () const
 As info, but as a string rather than a vector of properties. More...
 
std::string info_string (const iteminfo_query &parts, int batch=1, temperature_flag temperature=temperature_flag::TEMP_NORMAL) const
 
void basic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void med_info (const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void food_info (const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
 
void magazine_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void ammo_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gun_info (const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gunmod_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_protection_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void animal_armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_fit_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void book_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void battery_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void container_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void tool_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void component_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void repair_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void disassembly_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void qualities_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void bionic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void combat_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void contents_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void final_info (std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
 
float simulate_burn (fire_data &frd) const
 Calculate all burning calculations, but don't actually apply them to item. More...
 
bool burn (fire_data &frd)
 Burns the item. More...
 
const item_categoryget_category () const
 
bool reload (player &u, item_location loc, int qty)
 Reload item using ammo from location returning true if successful. More...
 
template<typename Archive >
void io (Archive &)
 
void serialize (JsonOut &json) const
 
void deserialize (JsonIn &jsin)
 
const std::string & symbol () const
 
int price (bool practical) const
 Returns the monetary value of an item. More...
 
bool display_stacked_with (const item &rhs, bool check_components=false) const
 Whether two items should stack when displayed in a inventory menu. More...
 
bool stacks_with (const item &rhs, bool check_components=false, bool skip_type_check=false) const
 
bool merge_charges (const item &rhs)
 Merge charges of the other item into this item. More...
 
units::mass weight (bool include_contents=true, bool integral=false) const
 
units::volume volume (bool integral=false) const
 Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. More...
 
units::volume base_volume () const
 Simplified, faster volume check for when processing time is important and exact volume is not. More...
 
units::volume corpse_volume (const mtype *corpse) const
 Volume check for corpses, helper for base_volume(). More...
 
int lift_strength () const
 Required strength to be able to successfully lift the item unaided by equipment. More...
 
Melee

The functions here assume the item is used in melee, even if's a gun or not a weapon at all.

Because the functions apply to all types of items, several of the is_* functions here may return true for the same item. This only indicates that it can be used in various ways.

int attack_cost () const
 Base number of moves (Creature::moves) that a single melee attack with this items takes. More...
 
int damage_melee (damage_type dt) const
 Damage of given type caused when this item is used as melee weapon. More...
 
damage_instance base_damage_melee () const
 All damage types this item deals when used in melee (no skill modifiers etc. More...
 
damage_instance base_damage_thrown () const
 All damage types this item deals when thrown (no skill modifiers etc. More...
 
double effective_dps (const player &guy, const monster &mon) const
 Calculate the item's effective damage per second past armor when wielded by a character against a monster. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc, const player &guy) const
 calculate effective dps against a stock set of monsters. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc) const
 
double average_dps (const player &guy) const
 return the average dps of the weapon against evaluation monsters More...
 
double ideal_ranged_dps (const Character &who, gun_mode &mode) const
 
bool is_two_handed (const Character &guy) const
 Whether the character needs both hands to wield this item. More...
 
bool is_melee (damage_type dt) const
 Is this item an effective melee weapon for the given damage type? More...
 
bool is_melee () const
 Is this item an effective melee weapon for any damage type? More...
 
skill_id melee_skill () const
 The most relevant skill used with this melee weapon. More...
 
int reach_range (const Character &guy) const
 Max range of melee attack this weapon can be used for. More...
 
void set_countdown (int num_turns)
 Sets time until activation for an item that will self-activate in the future. More...
 
bool use_charges (const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
 Consumes specified charges (or fewer) from this and any contained items. More...
 
bool on_drop (const tripoint &pos)
 Invokes item type's itype::drop_action. More...
 
bool on_drop (const tripoint &pos, map &map)
 Invokes item type's itype::drop_action. More...
 
bool use_amount (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 Consume a specific amount of items of a specific type. More...
 
bool allow_crafting_component () const
 Permits filthy components, should only be used as a helper in creating filters. More...
 
Containers

Containers come in two flavors:

bool is_container () const
 Whether this is container. More...
 
bool is_watertight_container () const
 Whether this is a container which can be used to store liquids. More...
 
bool is_container_empty () const
 Whether this item has no contents at all. More...
 
bool is_non_resealable_container () const
 Whether removing this item's contents will permanently alter it. More...
 
bool is_container_full (bool allow_bucket=false) const
 Whether this item has no more free capacity for its current content. More...
 
void fill_with (item &liquid, int amount=INFINITE_CHARGES)
 Fill item with liquid up to its capacity. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
 How much more of this liquid (in charges) can be put in this container. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, const Character &p, std::string *err=nullptr) const
 
units::volume get_container_capacity () const
 It returns the total capacity (volume) of the container for liquids. More...
 
units::volume get_total_capacity () const
 It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc. More...
 
void put_in (const item &payload)
 Puts the given item into this one, no checks are performed. More...
 
item in_its_container () const
 Returns this item into its default container. More...
 
item in_container (const itype_id &container_type) const
 
bool item_has_uses_recursive () const
 
bool is_funnel_container (units::volume &bigger_than) const
 Funnel related functions. More...
 
void add_rain_to_container (bool acid, int charges=1)
 Add charge(s) of rain to given container, possibly contaminating it. More...
 
int get_quality (const quality_id &id) const
 
std::map< quality_id, int > get_qualities () const
 
bool count_by_charges () const
 
int count () const
 If count_by_charges(), returns charges, otherwise 1. More...
 
bool craft_has_charges ()
 
void mod_charges (int mod)
 Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges. More...
 
bool actualize_rot (const tripoint &pnt, temperature_flag temperature, const weather_manager &weather)
 Whether the item has to be removed as it has rotten away completely. More...
 
auto calc_rot (time_point time, const units::temperature temp) const -> time_duration
 Returns rot of the item since last rot calculation. More...
 
time_duration minimum_freshness_duration (temperature_flag temperature) const
 Time that this item is guaranteed to stay fresh. More...
 
void mod_last_rot_check (time_duration processing_duration)
 This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble. More...
 
bool process_rot (const tripoint &pos)
 Update temperature for things like food Update rot for things that perish All items that rot also have temperature. More...
 
bool process_rot (bool seals, const tripoint &pos, player *carrier, temperature_flag flag, const weather_manager &weather_generator)
 
int get_comestible_fun () const
 
bool goes_bad () const
 whether an item is perishable (can rot) More...
 
bool goes_bad_after_opening () const
 whether an item is perishable (can rot), even if it is currently in a preserving container More...
 
time_duration get_shelf_life () const
 Get the shelf life of the item. More...
 
double get_relative_rot () const
 Get rot value relative to shelf life (or 0 if item does not spoil) More...
 
void set_relative_rot (double val)
 Set current item rot relative to shelf life (no-op if item does not spoil) More...
 
void set_rot (time_duration val)
 
int spoilage_sort_order () const
 Get time left to rot, ignoring fridge. More...
 
bool is_fresh () const
 an item is fresh if it is capable of rotting but still has a long shelf life remaining More...
 
bool is_going_bad () const
 an item is about to become rotten when shelf life has nearly elapsed More...
 
bool rotten () const
 returns true if item is now rotten after all shelf life has elapsed More...
 
bool has_rotten_away () const
 Whether the item has enough rot that it should get removed. More...
 
time_duration get_rot () const
 
void mod_rot (const time_duration &val)
 
time_duration brewing_time () const
 Time for this item to be fully fermented. More...
 
const std::vector< itype_id > & brewing_results () const
 The results of fermenting this item. More...
 
bool detonate (const tripoint &p, std::vector< item > &drops)
 Detonates the item and adds remains (if any) to drops. More...
 
bool will_explode_in_fire () const
 
Material(s) of the item

Each item is made of one or more materials (material_type).

Materials have properties that affect properties of the item (e.g. resistance against certain damage types).

Corpses inherit the material of the monster type.

const material_typeget_random_material () const
 Get a material reference to a random material that this item is made of. More...
 
const material_typeget_base_material () const
 Get the basic (main) material of this item. More...
 
const std::vector< material_id > & made_of () const
 The ids of all the materials this is made of. More...
 
const std::map< quality_id, int > & quality_of () const
 The ids of all the qualities this contains. More...
 
std::vector< const material_type * > made_of_types () const
 Same as made_of(), but returns the material_type directly. More...
 
bool made_of_any (const std::set< material_id > &mat_idents) const
 Check we are made of at least one of a set (e.g. More...
 
bool only_made_of (const std::set< material_id > &mat_idents) const
 Check we are made of only the materials (e.g. More...
 
bool made_of (const material_id &mat_ident) const
 Check we are made of this material (e.g. More...
 
bool contents_made_of (phase_id phase) const
 If contents nonempty, return true if item phase is same, else false. More...
 
bool made_of (phase_id phase) const
 Are we solid, liquid, gas, plasma? More...
 
std::vector< item_compget_uncraft_components () const
 Returns a list of components used to craft this item or the default components if it wasn't player-crafted. More...
 
bool conductive () const
 Whether the items is conductive. More...
 
bool flammable (int threshold=0) const
 Whether the items is flammable. More...
 
bool reinforceable () const
 Whether the item can be repaired beyond normal health. More...
 
int acid_resist (bool to_self=false, int base_env_resist=0) const
 Resistance against different damage types (damage_type). More...
 
int fire_resist (bool to_self=false, int base_env_resist=0) const
 
int bash_resist (bool to_self=false) const
 
int cut_resist (bool to_self=false) const
 
int stab_resist (bool to_self=false) const
 
int bullet_resist (bool to_self=false) const
 
void mitigate_damage (damage_unit &du) const
 Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type. More...
 
int damage_resist (damage_type dt, bool to_self=false) const
 Resistance provided by this item against damage type given by an enum. More...
 
int chip_resistance (bool worst=false) const
 Returns resistance to being damaged by attack against the item itself. More...
 
int damage () const
 How much damage has the item sustained? More...
 
int damage_level (int max) const
 Scale item damage to the given number of levels. More...
 
int min_damage () const
 Minimum amount of damage to an item (state of maximum repair) More...
 
int max_damage () const
 Maximum amount of damage to an item (state before destroyed) More...
 
float get_relative_health () const
 Relative item health. More...
 
bool mod_damage (int qty, damage_type dt)
 Apply damage to const itemrained by min_damage and max_damage. More...
 
bool mod_damage (int qty)
 same as other mod_damage, but uses DT_NULL as damage type. More...
 
bool inc_damage (damage_type dt)
 Increment item damage by itype::damage_scale constrained by max_damage. More...
 
bool inc_damage ()
 same as other inc_damage, but uses DT_NULL as damage type. More...
 
nc_color damage_color () const
 Provide color for UI display dependent upon current item damage level. More...
 
std::string damage_symbol () const
 Provide prefix symbol for UI display dependent upon current item damage level. More...
 
std::string durability_indicator (bool include_intact=false) const
 Provides a prefix for the durability state of the item. More...
 
const std::set< itype_id > & repaired_with () const
 If possible to repair this item what tools could potentially be used for this purpose? More...
 
bool already_used_by_player (const player &p) const
 Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player. More...
 
void mark_as_used_by_player (const player &p)
 Marks the item as being used by this specific player, it remains unmarked for other players. More...
 
bool is_filthy () const
 Marks the item as filthy, so characters with squeamish trait can't wear it. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
 This is called once each turn. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag, const weather_manager &weather_generator)
 
std::optional< tripointget_cable_target (Character *p, const tripoint &pos) const
 Gets the point (vehicle tile) the cable is connected to. More...
 
void reset_cable (player *p)
 Helper to bring a cable back to its initial state. More...
 
bool needs_processing () const
 Whether the item should be processed (by calling process). More...
 
int processing_speed () const
 The rate at which an item should be processed, in number of turns between updates. More...
 
void process_artifact (player *carrier, const tripoint &pos)
 Process and apply artifact effects. More...
 
void process_relic (Character &carrier)
 
bool destroyed_at_zero_charges () const
 
bool is_null () const
 
bool is_comestible () const
 
bool is_food () const
 
bool is_food_container () const
 
bool is_med_container () const
 
bool is_ammo_container () const
 
bool is_medication () const
 
bool is_bionic () const
 
bool is_magazine () const
 
bool is_battery () const
 
bool is_ammo_belt () const
 
bool is_bandolier () const
 
bool is_holster () const
 
bool is_ammo () const
 
bool is_pet_armor (bool on_pet=false) const
 
bool is_armor () const
 
bool is_book () const
 
bool is_map () const
 
bool is_salvageable () const
 
bool is_craft () const
 
bool is_deployable () const
 
bool is_tool () const
 
bool is_transformable () const
 
bool is_artifact () const
 
bool is_relic () const
 
bool is_bucket () const
 
bool is_bucket_nonempty () const
 
bool is_brewable () const
 
bool is_engine () const
 
bool is_wheel () const
 
bool is_fuel () const
 
bool is_toolmod () const
 
bool is_faulty () const
 
bool is_irremovable () const
 
bool is_unarmed_weapon () const
 
itemget_food ()
 
const itemget_food () const
 
int wind_resist () const
 How resistant clothes made of this material are to wind (0-100) More...
 
std::set< fault_idfaults_potential () const
 What faults can potentially occur with this item? More...
 
int wheel_area () const
 Returns the total area of this wheel or 0 if it isn't one. More...
 
float fuel_energy () const
 Returns energy of one charge of this item as fuel for an engine. More...
 
std::string fuel_pump_terrain () const
 Returns the string of the id of the terrain that pumps this fuel, if any. More...
 
bool has_explosion_data () const
 
struct fuel_explosion get_explosion_data ()
 
bool can_contain (const item &it) const
 Can this item have given item/itype as content? More...
 
bool can_contain (const itype &tp) const
 
bool is_reloadable () const
 Is it ever possible to reload this item? Only the base item is considered with any mods ignored. More...
 
bool can_reload_with (const ammotype &ammo) const
 Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo. More...
 
bool can_reload_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo. More...
 
bool is_reloadable_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo type at this moment. More...
 
bool can_unload_liquid () const
 Returns true if not empty if it's liquid, it's not currently frozen in resealable container. More...
 
bool is_dangerous () const
 
bool is_tainted () const
 Is item derived from a zombie? More...
 
bool is_soft () const
 Is this item flexible enough to be worn on body parts like antlers? More...
 
bool has_effect_when_wielded (art_effect_passive effect) const
 Does the item provide the artifact effect when it is wielded? More...
 
bool has_effect_when_worn (art_effect_passive effect) const
 Does the item provide the artifact effect when it is worn? More...
 
bool has_effect_when_carried (art_effect_passive effect) const
 Does the item provide the artifact effect when it is carried? More...
 
void set_snippet (const snippet_id &id)
 Set the snippet text (description) of this specific item, using the snippet library. More...
 
bool operator< (const item &other) const
 
bool operator== (const item &rhs) const
 LUA: We need this operator defined for Lua bindings to compile. More...
 
bool operator<= (const item &other) const
 LUA: We need this operator defined for Lua bindings to compile. More...
 
std::string components_to_string () const
 List of all components in printable form, empty if this item has no components. More...
 
uint64_t make_component_hash () const
 Creates a hash from the itype_ids of this item's components. More...
 
const itype_idtypeId () const
 return the unique identifier of the items underlying type More...
 
const itemget_contained () const
 Return a contained item (if any and only one). More...
 
bool spill_contents (Character &c)
 Unloads the item's contents. More...
 
bool spill_contents (const tripoint &pos)
 Unloads the item's contents. More...
 
bool can_holster (const item &obj, bool ignore=false) const
 Checks if item is a holster and currently capable of storing obj. More...
 
void on_wear (Character &p)
 Callback when a character starts wearing the item. More...
 
void on_takeoff (Character &p)
 Callback when a character takes off an item. More...
 
void on_wield (player &p, int mv=0)
 Callback when a player starts wielding the item. More...
 
void on_pickup (Character &p)
 Callback when a player starts carrying the item. More...
 
void on_contents_changed ()
 Callback when contents of the item are affected in any way other than just processing. More...
 
void on_damage (int qty, damage_type dt)
 Callback immediately before an item is damaged. More...
 
std::vector< trait_idmutations_from_wearing (const Character &guy) const
 
std::string type_name (unsigned int quantity=1) const
 Name of the item type (not the item), with proper plural. More...
 
int charges_per_volume (const units::volume &vol) const
 Number of (charges of) this item that fit into the given volume. More...
 
Item variables

Item variables can be used to store any value in the item.

The storage is persistent, it remains through saving & loading, it is copied when the item is moved etc. Each item variable is referred to by its name, so make sure you use a name that is not already used somewhere. You can directly store integer, floating point and string values. Data of other types must be converted to one of those to be stored. The set_var functions override the existing value. The get_var function return the value (if the variable exists), or the default value otherwise. The type of the default value determines which get_var function is used. All numeric values are returned as doubles and may be cast to the desired type. int v = itm.get_var("v", 0); // v will be an int double d = itm.get_var("v", 0.0); // d will be a double std::string s = itm.get_var("v", ""); // s will be a std::string // no default means empty string as default: auto n = itm.get_var("v"); // v will be a std::string

void set_var (const std::string &name, int value)
 
void set_var (const std::string &name, long long value)
 
void set_var (const std::string &name, long value)
 
void set_var (const std::string &name, double value)
 
double get_var (const std::string &name, double default_value) const
 
void set_var (const std::string &name, const tripoint &value)
 
tripoint get_var (const std::string &name, const tripoint &default_value) const
 
void set_var (const std::string &name, const std::string &value)
 
std::string get_var (const std::string &name, const std::string &default_value) const
 
std::string get_var (const std::string &name) const
 Get the variable, if it does not exists, returns an empty string. More...
 
bool has_var (const std::string &name) const
 Whether the variable is defined at all. More...
 
void erase_var (const std::string &name)
 Erase the value of the given variable. More...
 
void clear_vars ()
 Removes all item variables. More...
 
Item flags

If you use any new flags, add them to flags.json, add a comment to doc/JSON_FLAGS.md and make sure your new flag does not conflict with any existing flag.

Item flags are taken from the item type (itype::item_tags), but also from the item itself (item_tags). The item has the flag if it appears in either set.

Gun mods that are attached to guns also contribute their flags to the gun item.

bool has_flag (const std::string &flag) const
 
bool has_flag (const flag_str_id &flag) const
 
template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool has_any_flag (const Container &flags) const
 
bool has_own_flag (const std::string &flag) const
 Checks whether item itself has given flag (doesn't check item type or gunmods). More...
 
const FlagsSetTypeget_flags () const
 returs read-only set of flags of this item (not including flags from item type or gunmods) More...
 
itemset_flag (const std::string &flag)
 Idempotent filter setting an item specific flag. More...
 
itemunset_flag (const std::string &flag)
 Idempotent filter removing an item specific flag. More...
 
itemset_flag_recursive (const std::string &flag)
 Idempotent filter recursively setting an item specific flag on this item and its components. More...
 
void unset_flags ()
 Removes all item specific flags. More...
 
bool has_fault (const fault_id &fault) const
 Does this item have the specified fault. More...
 
Item properties

Properties are specific to an item type so unlike flags the meaning of a property may not be the same for two different item types.

Each item type can have multiple properties however duplicate property names are not permitted.

bool has_property (const std::string &prop) const
 
std::string get_property_string (const std::string &prop, const std::string &def="") const
 Get typed property for item. More...
 
int64_t get_property_int64_t (const std::string &prop, int64_t def=0) const
 
Light emitting items

Items can emit light either through the definition of their type (itype::light_emission) or through an item specific light data (light).

bool getlight (float &luminance, units::angle &width, units::angle &direction) const
 Directional light emission of the item. More...
 
int getlight_emit () const
 How much light (see lightmap.cpp) the item emits (it's assumed to be circular). More...
 
bool is_emissive () const
 Whether the item emits any light at all. More...
 
Seed data.
bool is_seed () const
 Whether this is actually a seed, the seed functions won't be of much use for non-seeds. More...
 
time_duration get_plant_epoch () const
 Time it takes to grow from one stage to another. More...
 
std::string get_plant_name () const
 The name of the plant as it appears in the various informational menus. More...
 
Armor related functions.

The functions here refer to values from islot_armor.

They only apply to armor items, those items can be worn. The functions are safe to call for any item, for non-armor they return a default value.

bool covers (body_part bp) const
 Whether this item (when worn) covers the given body part. More...
 
bool covers (const bodypart_id &bp) const
 
body_part_set get_covered_body_parts () const
 Bitset of all covered body parts. More...
 
body_part_set get_covered_body_parts (side s) const
 Bitset of all covered body parts, from a specific side. More...
 
bool is_sided () const
 Returns true if item is armor and can be worn on different sides of the body. More...
 
side get_side () const
 Returns side item currently worn on. More...
 
bool set_side (side s)
 Change the side on which the item is worn. More...
 
bool swap_side ()
 Swap the side on which the item is worn. More...
 
int get_warmth () const
 Returns the warmth value that this item has when worn. More...
 
int get_thickness () const
 Returns the islot_armor::thickness value, or 0 for non-armor. More...
 
layer_level get_layer () const
 Returns clothing layer for item. More...
 
int get_coverage () const
 Returns the relative coverage that this item has when worn. More...
 
int get_encumber_when_containing (const Character &, const units::volume &contents_volume) const
 Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents. More...
 
int get_encumber (const Character &) const
 Returns the encumbrance value that this item has when worn by given player. More...
 
units::volume get_storage () const
 Returns the storage amount (islot_armor::storage) that this item provides when worn. More...
 
float get_weight_capacity_modifier () const
 Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
units::mass get_weight_capacity_bonus () const
 Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
int get_env_resist (int override_base_resist=0) const
 Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn. More...
 
int get_base_env_resist_w_filter () const
 Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed. More...
 
bool is_power_armor () const
 Whether this is a power armor item. More...
 
const islot_armorfind_armor_data () const
 If this is an armor item, return its armor data. More...
 
bool is_worn_only_with (const item &it) const
 Returns true whether this item can be worn only when. More...
 
Pet armor related functions.

The functions here refer to values from islot_pet_armor.

They only apply to pet armor items, those items can be worn by pets. The functions are safe to call for any item, for non-pet armor they return a default value.

units::volume get_pet_armor_max_vol () const
 
units::volume get_pet_armor_min_vol () const
 
bodytype_id get_pet_armor_bodytype () const
 
Books

Book specific functions, apply to items that are books.

int get_chapters () const
 How many chapters the book has (if any). More...
 
int get_remaining_chapters (const Character &ch) const
 Get the number of unread chapters. More...
 
void mark_chapter_as_read (const Character &ch)
 Mark one chapter of the book as read by the given player. More...
 
std::vector< std::pair< const recipe *, int > > get_available_recipes (const player &u) const
 Enumerates recipes available from this book and the skill level required to use them. More...
 
Martial art techniques

See martialarts.h for further info.

bool has_technique (const matec_id &tech) const
 Whether the item supports a specific martial art technique (either through its type, or through its individual techniques). More...
 
std::set< matec_idget_techniques () const
 Returns all the martial art techniques that this items supports. More...
 
void add_technique (const matec_id &tech)
 Add the given technique to the item specific techniques. More...
 
std::vector< item * > toolmods ()
 Returns all toolmods currently attached to this item (always empty if item not a tool) More...
 
std::vector< const item * > toolmods () const
 
Gun and gunmod functions

Gun and gun mod functions.

Anything stated to apply to guns, applies to auxiliary gunmods as well (they are some kind of gun). Non-guns are items that are neither gun nor auxiliary gunmod.

bool is_gunmod () const
 
bool is_gun () const
 Can this item be used to perform a ranged attack? More...
 
units::energy energy_remaining () const
 Quantity of energy currently loaded in tool or battery. More...
 
int ammo_remaining () const
 Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod. More...
 
int ammo_capacity () const
 Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod. More...
 
int ammo_capacity (bool potential_capacity) const
 
int ammo_required () const
 Quantity of ammunition consumed per usage of tool or with each shot of gun. More...
 
bool ammo_sufficient (int qty=1) const
 Check if sufficient ammo is loaded for given number of uses. More...
 
int ammo_consume (int qty, const tripoint &pos)
 Consume ammo (if available) and return the amount of ammo that was consumed. More...
 
const itypeammo_data () const
 Specific ammo data, returns nullptr if item is neither ammo nor loaded with any. More...
 
itype_id ammo_current () const
 Specific ammo type, returns "null" if item is neither ammo nor loaded with any. More...
 
const std::set< ammotype > & ammo_types (bool conversion=true) const
 Set of ammo types (ammunition_type) used by item. More...
 
ammotype ammo_type () const
 Ammo type of an ammo item. More...
 
itype_id ammo_default (bool conversion=true) const
 Get default ammo used by item or a null id if item does not have a default ammo type. More...
 
itype_id common_ammo_default (bool conversion=true) const
 Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists. More...
 
std::set< ammo_effect_str_idammo_effects (bool with_ammo=true) const
 Get ammo effects for item optionally inclusive of any resulting from the loaded ammo. More...
 
std::string ammo_sort_name () const
 
int casings_count () const
 How many spent casings are contained within this item? More...
 
void casings_handle (const std::function< bool(item &)> &func)
 Apply predicate to each contained spent casing removing it if predicate returns true. More...
 
bool magazine_integral () const
 Does item have an integral magazine (as opposed to allowing detachable magazines) More...
 
itype_id magazine_default (bool conversion=true) const
 Get the default magazine type (if any) for the current effective ammo type. More...
 
std::set< itype_idmagazine_compatible (bool conversion=true) const
 Get compatible magazines (if any) for this item. More...
 
itemmagazine_current ()
 Currently loaded magazine (if any) More...
 
const itemmagazine_current () const
 
std::vector< item * > gunmods ()
 Returns all gunmods currently attached to this item (always empty if item not a gun) More...
 
std::vector< const item * > gunmods () const
 
itemgunmod_find (const itype_id &mod)
 Get first attached gunmod matching type or nullptr if no such mod or item is not a gun. More...
 
const itemgunmod_find (const itype_id &mod) const
 
ret_val< bool > is_gunmod_compatible (const item &mod) const
 
std::map< gun_mode_id, gun_modegun_all_modes () const
 Get all possible modes for this gun inclusive of any attached gunmods. More...
 
gun_mode gun_get_mode (const gun_mode_id &mode) const
 Check if gun supports a specific mode returning an invalid/empty mode if not. More...
 
gun_mode gun_current_mode () const
 Get the current mode for this gun (or an invalid mode if item is not a gun) More...
 
gun_mode_id gun_get_mode_id () const
 Get id of mode a gun is currently set to, e.g. More...
 
bool gun_set_mode (const gun_mode_id &mode)
 Try to set the mode for a gun, returning false if no such mode is possible. More...
 
void gun_cycle_mode ()
 Switch to the next available firing mode. More...
 
int sight_dispersion () const
 Get lowest dispersion of either integral or any attached sights. More...
 
sound_data gun_noise (bool burst=false) const
 Returns the sound of the gun being fired. More...
 
bool is_silent () const
 Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). More...
 
int gun_range (const player *p) const
 The weapons range in map squares. More...
 
int gun_range (bool with_ammo=true) const
 Summed range value of a gun, including values from mods. More...
 
double gun_recoil_multiplier (bool bipod=false) const
 Get multiplier on recoil considering handling and attached gunmods. More...
 
int gun_recoil (bool bipod=false) const
 Get effective recoil considering handling, loaded ammo and effects of attached gunmods. More...
 
damage_instance gun_damage (bool with_ammo=true) const
 Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods. More...
 
int gun_dispersion (bool with_ammo=true, bool with_scaling=true) const
 Summed dispersion of a gun, including values from mods. More...
 
skill_id gun_skill () const
 The skill used to operate the gun. More...
 
std::map< gunmod_location, int > get_mod_locations () const
 Get mod locations, including those added by other mods. More...
 
int get_free_mod_locations (const gunmod_location &location) const
 Number of mods that can still be installed into the given mod location, for non-guns it always returns 0. More...
 
bool is_firearm () const
 Does it require gunsmithing tools to repair. More...
 
int get_reload_time () const
 Returns the reload time of the gun. More...
 
Vehicle parts
int engine_displacement () const
 for combustion engines the displacement (cc) More...
 
- Public Member Functions inherited from visitable< item >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static item make_corpse (const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
 Make a corpse of the given monster type. More...
 

Bionics / CBMs

Functions specific to CBMs

enum class  sizing {
  human_sized_human_char = 0 , big_sized_human_char , small_sized_human_char , big_sized_big_char ,
  human_sized_big_char , small_sized_big_char , small_sized_small_char , human_sized_small_char ,
  big_sized_small_char , not_wearable
}
 
static const int INFINITE_CHARGES = INT_MAX
 
const itypetype
 
item_contents contents
 
std::list< itemcomponents
 
std::set< fault_idfaults
 What faults (if any) currently apply to this item. More...
 
FlagsSetType item_tags
 
int charges
 
units::energy energy
 
int recipe_charges = 1
 
int burnt = 0
 
int poison = 0
 
int frequency = 0
 
snippet_id snip_id = snippet_id::NULL_ID()
 
int irradiation = 0
 
int item_counter = 0
 
int mission_id = -1
 
int player_id = -1
 
bool encumbrance_update_ = false
 
char invlet = 0
 
bool active = false
 
safe_reference< Characteractivated_by
 
bool is_favorite = false
 
pimpl< item_drop_tokendrop_token
 Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class. More...
 
safe_reference_anchor anchor
 
const itypecurammo = nullptr
 
std::map< std::string, std::string > item_vars
 
const mtypecorpse = nullptr
 
std::string corpse_name
 
std::set< matec_idtechniques
 
cata::value_ptr< craft_datacraft_data_
 
cata::value_ptr< relicrelic_data
 
time_duration rot = 0_turns
 Accumulated rot, expressed as time the item has been in standard temperature. More...
 
time_point last_rot_check = calendar::turn_zero
 Time when the rot calculation was last performed. More...
 
time_point bday
 The time the item was created. More...
 
faction_id owner = faction_id::NULL_ID()
 
faction_id old_owner = faction_id::NULL_ID()
 
int damage_ = 0
 
light_emission light = nolight
 
bool is_upgrade () const
 Whether the CBM is an upgrade to another bionic module. More...
 
bool has_use () const
 Returns true if the item has any use function. More...
 
const use_functionget_use (const std::string &use_name) const
 Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents. More...
 
itemget_usable_item (const std::string &use_name)
 Checks this item and its contents (recursively) for types that have use_function with type use_name. More...
 
int units_remaining (const Character &ch, int limit=INT_MAX) const
 How many units (ammo or charges) are remaining? More...
 
bool units_sufficient (const Character &ch, int qty=-1) const
 Check if item has sufficient units (ammo or charges) remaining. More...
 
std::string get_corpse_name ()
 Returns name of deceased being if it had any or empty string if not. More...
 
bool has_label () const
 Returns true if item has "item_label" itemvar. More...
 
std::string label (unsigned int quantity=0) const
 Returns label from "item_label" itemvar and quantity. More...
 
bool has_infinite_charges () const
 
skill_id contextualize_skill (const skill_id &id) const
 Puts the skill in context of the item. More...
 
bool release_monster (const tripoint &target, int radius=0)
 
int contain_monster (const tripoint &target)
 
time_duration age () const
 
void set_age (const time_duration &age)
 
void legacy_fast_forward_time ()
 
time_point birthday () const
 
void set_birthday (const time_point &bday)
 
void handle_pickup_ownership (Character &c)
 
int get_gun_ups_drain () const
 
void validate_ownership () const
 
void set_old_owner (const faction_id &temp_owner)
 
void remove_old_owner () const
 
void set_owner (const faction_id &new_owner)
 
void set_owner (const Character &c)
 
void remove_owner () const
 
faction_id get_owner () const
 
faction_id get_old_owner () const
 
bool is_owned_by (const Character &c, bool available_to_take=false) const
 
bool is_old_owner (const Character &c, bool available_to_take=false) const
 
std::string get_owner_name () const
 
int get_min_str () const
 
const cata::value_ptr< islot_comestible > & get_comestible () const
 
const recipeget_making () const
 Get the stored recipe for in progress crafts. More...
 
int get_next_failure_point () const
 Get the failure point stored in this item. More...
 
void set_next_failure_point (const player &crafter)
 Calculates and sets the next failure point for an in progress craft. More...
 
bool handle_craft_failure (player &crafter)
 Handle failure during crafting. More...
 
requirement_data get_continue_reqs () const
 Returns requirement data representing what is needed to resume work on an in progress craft. More...
 
void inherit_flags (const item &parent, const recipe &making)
 Inherit applicable flags from the given parent item. More...
 
void inherit_flags (const std::list< item > &parents, const recipe &making)
 Inherit applicable flags from the given list of parent items. More...
 
void set_tools_to_continue (bool value)
 
bool has_tools_to_continue () const
 
void set_cached_tool_selections (const std::vector< comp_selection< tool_comp > > &selections)
 
const std::vector< comp_selection< tool_comp > > & get_cached_tool_selections () const
 
const std::vector< enchantment > & get_enchantments () const
 
double bonus_from_enchantments (const Character &owner, double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only. More...
 
double bonus_from_enchantments_wielded (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied. More...
 
const std::vector< relic_recharge > & get_relic_recharge_scheme () const
 
sizing get_sizing (const Character &, bool) const
 
void set_favorite (bool favorite)
 
bool has_clothing_mod () const
 
float get_clothing_mod_val (clothing_mod_type type) const
 
void update_clothing_mod_val ()
 
static std::string nname (const itype_id &id, unsigned int quantity=1)
 Returns the translated item name for the item with given id. More...
 
static bool count_by_charges (const itype_id &id)
 Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance. More...
 
bool use_amount_internal (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 
const use_functionget_use_internal (const std::string &use_name) const
 
bool process_internal (player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
 
bool is_reloadable_helper (const itype_id &ammo, bool now) const
 Helper for checking reloadability. More...
 
bool process_corpse (player *carrier, const tripoint &pos)
 
bool process_wet (player *carrier, const tripoint &pos)
 
bool process_litcig (player *carrier, const tripoint &pos)
 
bool process_extinguish (player *carrier, const tripoint &pos)
 
bool process_fake_smoke (player *carrier, const tripoint &pos)
 
bool process_fake_mill (player *carrier, const tripoint &pos)
 
bool process_cable (player *carrier, const tripoint &pos)
 
bool process_UPS (player *carrier, const tripoint &pos)
 
bool process_blackpowder_fouling (player *carrier)
 
bool process_tool (player *carrier, const tripoint &pos)
 

Additional Inherited Members

Detailed Description

Definition at line 209 of file item.h.

Member Typedef Documentation

◆ archive_type_tag

Definition at line 493 of file item.h.

◆ FlagsSetType

using item::FlagsSetType = cata::flat_set<std::string>

Definition at line 212 of file item.h.

Member Enumeration Documentation

◆ sizing

enum class item::sizing
strong
Enumerator
human_sized_human_char 
big_sized_human_char 
small_sized_human_char 
big_sized_big_char 
human_sized_big_char 
small_sized_big_char 
small_sized_small_char 
human_sized_small_char 
big_sized_small_char 
not_wearable 

Definition at line 2136 of file item.h.

2136 {
2137 human_sized_human_char = 0,
2138 big_sized_human_char,
2139 small_sized_human_char,
2140 big_sized_big_char,
2141 human_sized_big_char,
2142 small_sized_big_char,
2143 small_sized_small_char,
2144 human_sized_small_char,
2145 big_sized_small_char,
2146 not_wearable
2147 };

Constructor & Destructor Documentation

◆ item() [1/11]

item::item ( )

Definition at line 370 of file item.cpp.

371{
372 type = nullitem();
373 charges = 0;
374}
time_point bday
The time the item was created.
Definition: item.h:2237
int charges
Definition: item.h:2209
const itype * type
Definition: item.h:2170
static const itype * nullitem()
Definition: item.cpp:321
const time_point & start_of_cataclysm
Definition: calendar.cpp:33

References charges, nullitem(), and type.

Referenced by add_rain_to_container(), ammo_set(), vehicle_part::deserialize(), io(), item(), and split().

◆ item() [2/11]

item::item ( item &&  )
default

◆ item() [3/11]

item::item ( const item )
default

◆ item() [4/11]

item::item ( const itype_id id,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 436 of file item.cpp.

437 : item( & * id, turn, qty ) {}
item()
Definition: item.cpp:370
time_point turn
Definition: calendar.cpp:36

◆ item() [5/11]

item::item ( const itype type,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 376 of file item.cpp.

376 : type( type ), bday( turn )
377{
378 corpse = has_flag( flag_CORPSE ) ? &mtype_id::NULL_ID().obj() : nullptr;
380
381 if( qty >= 0 ) {
382 charges = qty;
383 } else {
384 if( type->tool && type->tool->rand_charges.size() > 1 ) {
385 const int charge_roll = rng( 1, type->tool->rand_charges.size() - 1 );
386 charges = rng( type->tool->rand_charges[charge_roll - 1], type->tool->rand_charges[charge_roll] );
387 } else {
389 }
390 }
391
393 itype_id nanofab_recipe = item_group::item_from( item_group_id( "nanofab_recipes" ) ).typeId();
394 set_var( "NANOFAB_ITEM_ID", nanofab_recipe.str() );
395 }
396
397 if( type->gun ) {
398 for( const itype_id &mod : type->gun->built_in_mods ) {
399 item it( mod, turn, qty );
400 it.set_flag( "IRREMOVABLE" );
401 put_in( it );
402 }
403 for( const itype_id &mod : type->gun->default_mods ) {
404 put_in( item( mod, turn, qty ) );
405 }
406
407 } else if( type->magazine ) {
408 if( type->magazine->count > 0 ) {
409 put_in( item( type->magazine->default_ammo, calendar::turn, type->magazine->count ) );
410 }
411
412 } else if( goes_bad() ) {
413 active = true;
415
416 } else if( type->tool ) {
417 if( ammo_remaining() && !ammo_types().empty() ) {
419 }
420 }
421
422 if( ( type->gun || type->tool ) && !magazine_integral() ) {
423 set_var( "magazine_converted", 1 );
424 }
425
426 if( !type->snippet_category.empty() ) {
428 }
429
430 // item always has any relic properties from itype.
431 if( type->relic_data ) {
433 }
434}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
Definition: item.h:210
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7384
bool active
Definition: item.h:2247
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:1000
void set_var(const std::string &name, int value)
Definition: item.cpp:1005
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:595
bool goes_bad() const
whether an item is perishable (can rot)
Definition: item.cpp:5525
const mtype * corpse
Definition: item.h:2182
snippet_id snip_id
Definition: item.h:2216
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8359
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7662
bool has_flag(const std::string &flag) const
Definition: item.cpp:5330
itype_id ammo_default(bool conversion=true) const
Get default ammo used by item or a null id if item does not have a default ammo type.
Definition: item.cpp:7598
time_point last_rot_check
Time when the rot calculation was last performed.
Definition: item.h:2235
const std::set< ammotype > & ammo_types(bool conversion=true) const
Set of ammo types (ammunition_type) used by item.
Definition: item.cpp:7567
int item_counter
Definition: item.h:2218
cata::value_ptr< relic > relic_data
Definition: item.h:2207
snippet_id random_id_from_category(const std::string &cat) const
Returns the id of a random snippet out of the given category.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:63
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:263
static const string_id< mtype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
static const std::string flag_NANOFAB_TEMPLATE("NANOFAB_TEMPLATE")
static const std::string flag_CORPSE("CORPSE")
item item_from(const item_group_id &group_id, const time_point &birthday)
Returns a random item from the item group, handles packaged food by putting it into its container and...
Definition: item_group.cpp:589
std::string snippet_category
Definition: itype.h:878
cata::value_ptr< islot_gun > gun
Definition: itype.h:830
cata::value_ptr< islot_tool > tool
Definition: itype.h:820
int charges_default() const
Definition: itype.cpp:98
cata::value_ptr< relic > relic_data
Definition: itype.h:838
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:832
int countdown_interval
Default countdown interval (if any) for item.
Definition: itype.h:924
snippet_library SNIPPET
string_id< Item_group > item_group_id
Definition: type_id.h:77

References active, ammo_default(), ammo_remaining(), ammo_set(), ammo_types(), bday, charges, itype::charges_default(), corpse, itype::countdown_interval, flag_CORPSE(), flag_NANOFAB_TEMPLATE(), goes_bad(), itype::gun, has_flag(), item(), item_counter, item_group::item_from(), last_rot_check, itype::magazine, magazine_integral(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), put_in(), snippet_library::random_id_from_category(), relic_data, itype::relic_data, rng(), set_flag(), set_var(), snip_id, SNIPPET, itype::snippet_category, string_id< T >::str(), itype::tool, calendar::turn, type, and typeId().

◆ item() [6/11]

item::item ( const itype_id id,
time_point  turn,
default_charges_tag  tag 
)

Definition at line 442 of file item.cpp.

443 : item( & * id, turn, tag ) {}

◆ item() [7/11]

item::item ( const itype type,
time_point  turn,
default_charges_tag   
)

Definition at line 439 of file item.cpp.

440 : item( type, turn, type->charges_default() ) {}

◆ item() [8/11]

item::item ( const itype_id id,
time_point  turn,
solitary_tag  tag 
)

Definition at line 448 of file item.cpp.

449 : item( & * id, turn, tag ) {}

◆ item() [9/11]

item::item ( const itype type,
time_point  turn,
solitary_tag   
)

Definition at line 445 of file item.cpp.

446 : item( type, turn, type->count_by_charges() ? 1 : -1 ) {}
bool count_by_charges() const
Definition: itype.cpp:93

◆ item() [10/11]

item::item ( const recipe rec,
int  qty,
std::list< item items,
std::vector< item_comp selections 
)

For constructing in-progress crafts.

Definition at line 469 of file item.cpp.

470 : item( "craft", calendar::turn, qty )
471{
472 craft_data_ = cata::make_value<craft_data>();
473 craft_data_->making = rec;
474 components = items;
475 craft_data_->comps_used = selections;
476
477 if( is_food() ) {
478 active = true;
480 if( goes_bad() ) {
481 const item *most_rotten = get_most_rotten_component( *this );
482 if( most_rotten ) {
483 set_relative_rot( most_rotten->get_relative_rot() );
484 }
485 }
486 }
487
488 for( item &component : components ) {
489 for( const std::string &f : component.item_tags ) {
490 if( json_flag::get( f ).craft_inherit() ) {
491 set_flag( f );
492 }
493 }
494 for( const std::string &f : component.type->get_flags() ) {
495 if( json_flag::get( f ).craft_inherit() ) {
496 set_flag( f );
497 }
498 }
499 }
500 // this extra section is so that in-progress crafts will correctly display expected flags.
501 for( const std::string &flag : rec->flags_to_delete ) {
502 unset_flag( flag );
503 }
504}
cata::value_ptr< craft_data > craft_data_
Definition: item.h:2204
std::list< item > components
Definition: item.h:2172
bool is_food() const
Definition: item.cpp:6602
item & set_flag(const std::string &flag)
Idempotent filter setting an item specific flag.
Definition: item.cpp:5359
item & unset_flag(const std::string &flag)
Idempotent filter removing an item specific flag.
Definition: item.cpp:5365
void set_relative_rot(double val)
Set current item rot relative to shelf life (no-op if item does not spoil)
Definition: item.cpp:5566
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5558
static const json_flag & get(const std::string &id)
Fetches flag definition (or null flag if not found)
Definition: flag.cpp:70
std::set< std::string > flags_to_delete
Definition: recipe.h:115
static const item * get_most_rotten_component(const item &craft)
Definition: item.cpp:456
itype_id type
Definition: requirements.h:58
const FlagsSetType & get_flags() const
Definition: itype.cpp:156

References active, bday, components, craft_data_, recipe::flags_to_delete, json_flag::get(), itype::get_flags(), get_most_rotten_component(), get_relative_rot(), goes_bad(), is_food(), last_rot_check, set_flag(), set_relative_rot(), component::type, and unset_flag().

◆ item() [11/11]

template<typename... Args>
item::item ( const std::string &  itype,
Args &&...  args 
)
inline

Definition at line 240 of file item.h.

240 :
241 item( itype_id( itype ), std::forward<Args>( args )... )
242 {}
Definition: itype.h:805

◆ ~item()

item::~item ( )
default

Member Function Documentation

◆ acid_resist()

int item::acid_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Resistance against different damage types (damage_type).

Larger values means more resistance are thereby better, but there is no absolute value to compare them to. The values can be interpreted as chance (one_in) of damaging the item when exposed to the type of damage.

Parameters
to_selfIf this is true, it returns item's own resistance, not one it gives to wearer.
base_env_resistWill override the base environmental resistance (to allow hypothetical calculations for gas masks).

Definition at line 6137 of file item.cpp.

6138{
6139 if( to_self ) {
6140 // Currently no items are damaged by acid
6141 return INT_MAX;
6142 }
6143
6144 float resist = 0.0;
6146 if( is_null() ) {
6147 return 0.0;
6148 }
6149
6150 const std::vector<const material_type *> mat_types = made_of_types();
6151 if( !mat_types.empty() ) {
6152 // Not sure why cut and bash get an armor thickness bonus but acid doesn't,
6153 // but such is the way of the code.
6154
6155 for( const material_type *mat : mat_types ) {
6156 resist += mat->acid_resist();
6157 }
6158 // Average based on number of materials.
6159 resist /= mat_types.size();
6160 }
6161
6162 const int env = get_env_resist( base_env_resist );
6163 if( env < 10 ) {
6164 // Low env protection means it doesn't prevent acid seeping in.
6165 resist *= env / 10.0f;
6166 }
6167
6168 return std::lround( resist + mod );
6169}
float get_clothing_mod_val(clothing_mod_type type) const
Definition: item.cpp:10167
bool is_null() const
Definition: item.cpp:737
std::vector< const material_type * > made_of_types() const
Same as made_of(), but returns the material_type directly.
Definition: item.cpp:6436
int get_env_resist(int override_base_resist=0) const
Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides whe...
Definition: item.cpp:5773
@ clothing_mod_type_acid
Definition: clothing_mod.h:17

References clothing_mod_type_acid, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ activate()

item & item::activate ( )

Filter converting instance to active state.

Definition at line 562 of file item.cpp.

563{
564 if( active ) {
565 return *this; // no-op
566 }
567
568 if( type->countdown_interval > 0 ) {
570 }
571
572 active = true;
573
574 return *this;
575}

References active, itype::countdown_interval, item_counter, and type.

Referenced by iuse::cable_attach(), make_gun_projectile(), process(), and process_internal().

◆ actualize_rot()

bool item::actualize_rot ( const tripoint pnt,
temperature_flag  temperature,
const weather_manager weather 
)

Whether the item has to be removed as it has rotten away completely.

May change the item as it calls process_rot()

Parameters
pntThe position of the item on the current map.
temperatureFlag for special locations that affect temperature.
weatherWeather manager to supply temperature.
Returns
true if the item has rotten away and should be removed, false otherwise.

Definition at line 8805 of file item.cpp.

8807{
8808 if( goes_bad() ) {
8809 return process_rot( false, pnt, nullptr, temperature, weather );
8810 } else if( type->container && type->container->preserves ) {
8811 // Containers like tin cans preserves all items inside, they do not rot at all.
8812 return false;
8813 } else if( type->container && type->container->seals ) {
8814 // Items inside rot but do not vanish as the container seals them in.
8815 for( item *c : contents.all_items_top() ) {
8816 if( c->goes_bad() ) {
8817 c->process_rot( true, pnt, nullptr, temperature, weather );
8818 }
8819 }
8820 return false;
8821 } else {
8822 std::vector<item *> removed_items;
8823 // Check and remove rotten contents, but always keep the container.
8824 for( item *it : contents.all_items_top() ) {
8825 if( it->actualize_rot( pnt, temperature, weather ) ) {
8826 removed_items.push_back( it );
8827 }
8828 }
8829 for( item *it : removed_items ) {
8830 remove_item( *it );
8831 }
8832
8833 return false;
8834 }
8835}
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
item_contents contents
Definition: item.h:2171
bool process_rot(const tripoint &pos)
Update temperature for things like food Update rot for things that perish All items that rot also hav...
Definition: item.cpp:8952
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:565
constexpr double c
Definition: magic.cpp:1032
quantity< int, temperature_in_millidegree_celsius_tag > temperature
cata::value_ptr< islot_container > container
Slots for various item type properties.
Definition: itype.h:819

References item_contents::all_items_top(), c, itype::container, contents, goes_bad(), process_rot(), visitable< item >::remove_item(), and type.

◆ add_technique()

void item::add_technique ( const matec_id tech)

Add the given technique to the item specific techniques.

Note that other items of the same type are not affected by this.

Definition at line 5471 of file item.cpp.

5472{
5473 techniques.insert( tech );
5474}
std::set< matec_id > techniques
Definition: item.h:2184

References techniques.

Referenced by mdeath::jabberwock().

◆ age()

◆ allow_crafting_component()

bool item::allow_crafting_component ( ) const

Permits filthy components, should only be used as a helper in creating filters.

Definition at line 8539 of file item.cpp.

8540{
8541 if( is_toolmod() && is_irremovable() ) {
8542 return false;
8543 }
8544
8545 // vehicle batteries are implemented as magazines of charge
8546 if( is_magazine() && ammo_types().count( ammo_battery ) ) {
8547 return true;
8548 }
8549
8550 // fixes #18886 - turret installation may require items with irremovable mods
8551 if( is_gun() ) {
8552 bool valid = true;
8553 visit_items( [&]( const item * it ) {
8554 if( this == it ) {
8555 return VisitResponse::NEXT;
8556 }
8557 if( !( it->is_magazine() || ( it->is_gunmod() && it->is_irremovable() ) ) ) {
8558 valid = false;
8559 return VisitResponse::ABORT;
8560 }
8561 return VisitResponse::NEXT;
8562 } );
8563 return valid;
8564 }
8565
8566 return contents.empty();
8567}
bool empty() const
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:6020
bool is_irremovable() const
Definition: item.cpp:6785
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6527
bool is_toolmod() const
Definition: item.cpp:6775
bool is_gunmod() const
Definition: item.cpp:6557
bool is_magazine() const
Definition: item.cpp:6567
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:423
static const ammotype ammo_battery("battery")

References ammo_battery, ammo_types(), contents, count(), item_contents::empty(), is_gun(), is_gunmod(), is_irremovable(), is_magazine(), is_toolmod(), NEXT, and visitable< item >::visit_items().

◆ already_used_by_player()

bool item::already_used_by_player ( const player p) const

Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player.

Definition at line 8854 of file item.cpp.

8855{
8856 const auto it = item_vars.find( USED_BY_IDS );
8857 if( it == item_vars.end() ) {
8858 return false;
8859 }
8860 // USED_BY_IDS always starts *and* ends with a ';', the search string
8861 // ';<id>;' matches at most one part of USED_BY_IDS, and only when exactly that
8862 // id has been added.
8863 const std::string needle = string_format( ";%d;", p.getID().get_value() );
8864 return it->second.find( needle ) != std::string::npos;
8865}
character_id getID() const
Definition: character.cpp:494
int get_value() const
Definition: character_id.h:23
std::map< std::string, std::string > item_vars
Definition: item.h:2181
static const std::string USED_BY_IDS("USED_BY_IDS")
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by tname(), and reveal_map_actor::use().

◆ ammo_capacity() [1/2]

◆ ammo_capacity() [2/2]

int item::ammo_capacity ( bool  potential_capacity) const
Parameters
potential_capacitywhether to try a default magazine if necessary

Definition at line 7416 of file item.cpp.

7417{
7418 int res = 0;
7419
7420 const item *mag = magazine_current();
7421 if( mag ) {
7422 return mag->ammo_capacity();
7423 }
7424
7425 if( is_tool() ) {
7426 res = type->tool->max_charges;
7427 if( res == 0 && magazine_default() && potential_capacity ) {
7428 res = magazine_default()->magazine->capacity;
7429 }
7430 for( const item *e : toolmods() ) {
7431 res *= e->type->mod->capacity_multiplier;
7432 }
7433 }
7434
7435 if( is_gun() ) {
7436 res = type->gun->clip;
7437 for( const item *e : gunmods() ) {
7438 res *= e->type->mod->capacity_multiplier;
7439 }
7440 }
7441
7442 if( is_magazine() ) {
7443 res = type->magazine->capacity;
7444 }
7445
7446 if( is_bandolier() ) {
7447 return dynamic_cast<const bandolier_actor *>
7448 ( type->get_use( "bandolier" )->get_actor_ptr() )->capacity;
7449 }
7450
7451 return res;
7452}
Store ammo and later reload using it.
Definition: iuse_actor.h:884
std::vector< item * > toolmods()
Returns all toolmods currently attached to this item (always empty if item not a tool)
Definition: item.cpp:5476
bool is_tool() const
Definition: item.cpp:6968
itype_id magazine_default(bool conversion=true) const
Get the default magazine type (if any) for the current effective ammo type.
Definition: item.cpp:7677
bool is_bandolier() const
Definition: item.cpp:6582
item * magazine_current()
Currently loaded magazine (if any)
Definition: item.cpp:7724
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7737
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:166
iuse_actor * get_actor_ptr()
Definition: iuse.h:316

References ammo_capacity(), use_function::get_actor_ptr(), itype::get_use(), itype::gun, gunmods(), is_bandolier(), is_gun(), is_magazine(), is_tool(), itype::magazine, magazine_current(), magazine_default(), itype::tool, toolmods(), and type.

◆ ammo_consume()

int item::ammo_consume ( int  qty,
const tripoint pos 
)

Consume ammo (if available) and return the amount of ammo that was consumed.

Parameters
qtymaximum amount of ammo that should be consumed
poscurrent location of item, used for ejecting magazines and similar effects
Returns
amount of ammo consumed which will be between 0 and qty

Definition at line 7482 of file item.cpp.

7483{
7484 if( qty < 0 ) {
7485 debugmsg( "Cannot consume negative quantity of ammo for %s", tname() );
7486 return 0;
7487 }
7488
7489 item *mag = magazine_current();
7490 if( mag ) {
7491 const int res = mag->ammo_consume( qty, pos );
7492 if( res && ammo_remaining() == 0 ) {
7493 if( mag->has_flag( flag_MAG_DESTROY ) ) {
7494 remove_item( *mag );
7495 } else if( mag->has_flag( flag_MAG_EJECT ) ) {
7496 get_map().add_item( pos, *mag );
7497 remove_item( *mag );
7498 }
7499 }
7500 return res;
7501 }
7502
7503 if( is_magazine() ) {
7504 int need = qty;
7505 while( !contents.empty() ) {
7506 item &e = contents.front();
7507 if( need >= e.charges ) {
7508 need -= e.charges;
7510 } else {
7511 e.charges -= need;
7512 need = 0;
7513 break;
7514 }
7515 }
7516 return qty - need;
7517
7518 } else if( is_tool() || is_gun() ) {
7519 qty = std::min( qty, charges );
7521 avatar &you = get_avatar();
7524 }
7525 charges -= qty;
7526 if( charges == 0 ) {
7527 curammo = nullptr;
7528 }
7529 return qty;
7530 }
7531
7532 return 0;
7533}
avatar & get_avatar()
Definition: avatar.cpp:105
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1925
units::energy get_power_level() const
Definition: character.cpp:1905
Definition: avatar.h:55
item & front()
this is an artifact of the previous code using front() everywhere for contents.
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4576
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7482
const itype * curammo
Definition: item.h:2180
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4455
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:75
static const std::string flag_USES_BIONIC_POWER("USES_BIONIC_POWER")
static const std::string flag_MAG_DESTROY("MAG_DESTROY")
static const std::string flag_MAG_EJECT("MAG_EJECT")
map & get_map()
Definition: map.cpp:148
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References map::add_item(), ammo_consume(), ammo_remaining(), charges, contents, curammo, debugmsg, item_contents::empty(), flag_MAG_DESTROY(), flag_MAG_EJECT(), flag_USES_BIONIC_POWER(), units::from_kilojoule(), item_contents::front(), get_avatar(), get_map(), Character::get_power_level(), has_flag(), is_gun(), is_magazine(), is_tool(), magazine_current(), Character::mod_power_level(), visitable< item >::remove_item(), tname(), and units::to_kilojoule().

Referenced by ammo_consume(), vehicle_part::ammo_consume(), Character::consume_charges(), iuse::einktabletpc(), ranged::fire_gun(), activity_handlers::game_do_turn(), iuse::gasmask(), iuse::multicooker(), iuse::note_bionics(), activity_handlers::oxytorch_do_turn(), npc::pretend_fire(), process_tool(), reload(), activity_handlers::repair_item_finish(), toolweapon_on(), and activity_handlers::vibe_do_turn().

◆ ammo_current()

itype_id item::ammo_current ( ) const

Specific ammo type, returns "null" if item is neither ammo nor loaded with any.

Definition at line 7561 of file item.cpp.

7562{
7563 const itype *ammo = ammo_data();
7564 return ammo ? ammo->get_id() : itype_id::NULL_ID();
7565}
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7535
const itype_id & get_id() const
Definition: itype.cpp:88

References ammo_data(), itype::get_id(), and string_id< itype >::NULL_ID().

Referenced by vehicle_part::ammo_current(), turret_data::ammo_options(), npc::confident_gun_mode_range(), display_name(), aim_activity_actor::do_turn(), avatar_action::fire_wielded_weapon(), get_remaining_capacity_for_liquid(), ranged::get_shape_factory(), gun_noise(), npc_ai::gun_value(), ideal_ranged_dps(), is_reloadable_helper(), make_gun_projectile(), parse_tags(), remove_ammo(), activity_handlers::repair_item_finish(), stacks_with(), avatar_funcs::unload_item(), iuse_transform::use(), and weight().

◆ ammo_data()

const itype * item::ammo_data ( ) const

Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.

Definition at line 7535 of file item.cpp.

7536{
7537 const item *mag = magazine_current();
7538 if( mag ) {
7539 return mag->ammo_data();
7540 }
7541
7542 if( is_ammo() ) {
7543 return type;
7544 }
7545
7546 if( is_magazine() ) {
7547 return !contents.empty() ? contents.front().ammo_data() : nullptr;
7548 }
7549
7550 auto mods = is_gun() ? gunmods() : toolmods();
7551 for( const item *e : mods ) {
7552 if( !e->type->mod->ammo_modifier.empty() && e->ammo_current() &&
7553 e->ammo_current().is_valid() ) {
7554 return &*e->ammo_current();
7555 }
7556 }
7557
7558 return curammo;
7559}
bool is_ammo() const
Definition: item.cpp:6592

References ammo_data(), contents, curammo, item_contents::empty(), item_contents::front(), gunmods(), is_ammo(), is_gun(), is_magazine(), magazine_current(), toolmods(), and type.

Referenced by ammo_current(), ammo_data(), turret_data::ammo_data(), ammo_effects(), ammo_info(), cycle_action(), Character::deactivate_bionic(), avatar_action::fire_wielded_weapon(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), ranged::handle_gun_damage(), is_reloadable_helper(), make_gun_projectile(), Item_modifier::modify(), price(), character_funcs::select_ammo(), target_ui::update_ammo_range_from_gun_mode(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_default()

itype_id item::ammo_default ( bool  conversion = true) const

Get default ammo used by item or a null id if item does not have a default ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id::NULL_ID() if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7598 of file item.cpp.

7599{
7600 if( is_magazine() ) {
7601 return type->magazine->default_ammo;
7602 }
7603
7604 const std::set<ammotype> &atypes = ammo_types( conversion );
7605 if( !atypes.empty() ) {
7606 itype_id res = ammotype( *atypes.begin() )->default_ammotype();
7607 if( !res.is_empty() ) {
7608 return res;
7609 }
7610 }
7611 return itype_id::NULL_ID();
7612}
const itype_id & default_ammotype() const
Definition: ammo.h:21
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:306
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References ammo_types(), ammunition_type::default_ammotype(), string_id< T >::is_empty(), is_magazine(), itype::magazine, string_id< itype >::NULL_ID(), and type.

Referenced by basecamp::add_resource(), turret_data::ammo_current(), crafting::complete_disassemble(), game::dump_stats(), npc::enough_time_to_reload(), inventory::form_from_map(), gun_info(), npc_ai::gun_value(), ideal_ranged_dps(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), starting_inv(), iexamine::use_furn_fake_item(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_effects()

std::set< ammo_effect_str_id > item::ammo_effects ( bool  with_ammo = true) const

Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.

Definition at line 7630 of file item.cpp.

7631{
7632 if( !is_gun() ) {
7633 return std::set<ammo_effect_str_id>();
7634 }
7635
7636 std::set<ammo_effect_str_id> res = type->gun->ammo_effects;
7637 if( with_ammo && ammo_data() ) {
7638 res.insert( ammo_data()->ammo->ammo_effects.begin(), ammo_data()->ammo->ammo_effects.end() );
7639 }
7640
7641 for( const item *mod : gunmods() ) {
7642 res.insert( mod->type->gunmod->ammo_effects.begin(), mod->type->gunmod->ammo_effects.end() );
7643 }
7644
7645 return res;
7646}

References ammo_data(), itype::gun, gunmods(), is_gun(), and type.

Referenced by turret_data::ammo_effects(), gun_noise(), ranged::handle_gun_damage(), and make_gun_projectile().

◆ ammo_info()

void item::ammo_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1909 of file item.cpp.

1911{
1912 if( is_gun() || !ammo_data() || !parts->test( iteminfo_parts::AMMO_REMAINING_OR_TYPES ) ) {
1913 return;
1914 }
1915
1916 const std::string space = " ";
1917 if( ammo_remaining() > 0 ) {
1918 info.emplace_back( "AMMO", _( "<bold>Ammunition</bold>: " ),
1919 ammo_data()->nname( ammo_remaining() ) );
1920 } else if( is_ammo() ) {
1921 info.emplace_back( "AMMO", _( "<bold>Ammunition type</bold>: " ), ammo_type()->name() );
1922 }
1923
1924 const islot_ammo &ammo = *ammo_data()->ammo;
1925 if( !ammo.damage.empty() || ammo.force_stat_display ) {
1926 bool has_flat_dmg = !ammo.damage.empty() && ammo.damage.damage_units.front().amount > 0;
1927 bool display_flat_dmg = parts->test( iteminfo_parts::AMMO_DAMAGE_VALUE );
1928 // TODO: Multiple units
1929 bool has_dmg_multiplier = ammo.damage.damage_units.front().damage_multiplier != 1.0;
1930 bool display_dmg_multiplier = parts->test( iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL );
1931 bool didnt_print_dmg = false;
1932 if( has_flat_dmg && has_dmg_multiplier
1933 && has_dmg_multiplier && display_dmg_multiplier ) {
1934 info.emplace_back( "AMMO", _( "Damage: " ), "",
1936 info.emplace_back( "AMMO", "/", "",
1938 ammo.damage.damage_units.front().damage_multiplier );
1939 // Messy ifs...
1940 } else if( display_dmg_multiplier && ( has_dmg_multiplier || !has_flat_dmg ) ) {
1941 info.emplace_back( "AMMO", _( "Damage multiplier: " ), "",
1943 ammo.damage.damage_units.front().damage_multiplier );
1944 } else if( display_flat_dmg ) {
1945 info.emplace_back( "AMMO", _( "Damage: " ), "",
1947 } else {
1948 didnt_print_dmg = true;
1949 }
1950
1951 // Ugly, but handles edge cases better than mandatory space
1952 static const std::string no_space;
1953 const std::string &maybe_space = didnt_print_dmg ? no_space : space;
1954
1955 // TODO: Deduplicate with damage display
1956 bool has_flat_arpen = get_ranged_pierce( ammo ) != 0;
1957 bool display_flat_arpen = parts->test( iteminfo_parts::AMMO_DAMAGE_AP );
1958 bool has_armor_mult = get_ranged_armor_mult( ammo ) != 1.0;
1959 bool display_armor_mult = parts->test( iteminfo_parts::AMMO_DAMAGE_AP_PROPORTIONAL );
1960 if( has_flat_arpen && display_flat_arpen
1961 && has_armor_mult && display_armor_mult ) {
1962 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), "",
1964 info.emplace_back( "AMMO", "/", "",
1966 get_ranged_armor_mult( ammo ) );
1967 } else if( has_armor_mult && display_armor_mult ) {
1968 info.emplace_back( "AMMO", maybe_space + _( "Armor multiplier: " ), "",
1970 } else if( display_flat_arpen ) {
1971 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), get_ranged_pierce( ammo ) );
1972 }
1973 if( parts->test( iteminfo_parts::AMMO_DAMAGE_RANGE ) ) {
1974 info.emplace_back( "AMMO", _( "Range: " ), "", iteminfo::no_newline, ammo.shape
1975 ? static_cast<int>( ammo.shape->get_range() )
1976 : ammo.range );
1977 }
1979 info.emplace_back( "AMMO", space + _( "Dispersion: " ), "",
1981 }
1983 info.emplace_back( "AMMO", _( "Recoil: " ), "",
1985 }
1986 }
1987
1988 // TODO: De-hardcode. Have it imply a flag? Just include description_on_item in ammo_effect struct?
1989 std::vector<std::string> fx;
1990 if( ammo.shape &&
1991 parts->test( iteminfo_parts::AMMO_SHAPE ) ) {
1992 fx.emplace_back( string_format(
1993 _( "This ammo will produce effects with the following shape:\n<bold>%s</bold>" ),
1994 ammo.shape->get_description() ) );
1995 }
1996 if( ammo.ammo_effects.count( ammo_effect_RECYCLED ) &&
1998 fx.emplace_back( _( "This ammo has been <bad>hand-loaded</bad>." ) );
1999 }
2000 if( ammo.ammo_effects.count( ammo_effect_BLACKPOWDER ) &&
2002 fx.emplace_back(
2003 _( "This ammo has been loaded with <bad>blackpowder</bad>, and will quickly "
2004 "clog up most guns, and cause rust if the gun is not cleaned." ) );
2005 }
2006 if( ammo.ammo_effects.count( ammo_effect_NEVER_MISFIRES ) &&
2008 fx.emplace_back( _( "This ammo <good>never misfires</good>." ) );
2009 }
2010 if( ammo.ammo_effects.count( ammo_effect_INCENDIARY ) &&
2012 fx.emplace_back( _( "This ammo <neutral>starts fires</neutral>." ) );
2013 }
2014 if( !fx.empty() ) {
2016 for( const std::string &e : fx ) {
2017 info.emplace_back( "AMMO", e );
2018 }
2019 }
2020}
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9929
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3993
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7590
bool test(const iteminfo_parts &value) const
static const ammo_effect_str_id ammo_effect_NEVER_MISFIRES("NEVER_MISFIRES")
static float get_ranged_armor_mult(const common_ranged_data &ranged)
Definition: item.cpp:1105
static const ammo_effect_str_id ammo_effect_INCENDIARY("INCENDIARY")
static const ammo_effect_str_id ammo_effect_BLACKPOWDER("BLACKPOWDER")
static void insert_separation_line(std::vector< iteminfo > &info)
Definition: item.cpp:1306
static int get_ranged_pierce(const common_ranged_data &ranged)
Definition: item.cpp:1096
static const ammo_effect_str_id ammo_effect_RECYCLED("RECYCLED")
@ AMMO_DAMAGE_AP_PROPORTIONAL
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4140
int dispersion
Dispersion "bonus" from gun.
Definition: itype.h:421
damage_instance damage
Damage, armor piercing and multipliers for each.
Definition: itype.h:413
int range
Range bonus from gun.
Definition: itype.h:417
std::vector< damage_unit > damage_units
Definition: damage.h:52
float total_damage() const
Definition: damage.cpp:75
bool empty() const
Definition: damage.cpp:88
std::optional< bool > force_stat_display
Some combat ammo might not have a damage value Set this to make it show as combat ammo anyway.
Definition: itype.h:702
std::optional< shape_factory > shape
AoE shape or null if it's a projectile.
Definition: itype.h:707
int recoil
Recoil (per shot), roughly equivalent to kinetic energy (in Joules)
Definition: itype.h:682
std::set< ammo_effect_str_id > ammo_effects
See ammo_effect struct.
Definition: itype.h:674
@ no_newline
Do not follow with a newline.
Definition: item.h:146
@ is_decimal
Print as decimal rather than integer.
Definition: item.h:144
@ lower_is_better
Lower values are better for this stat.
Definition: item.h:147
cata::value_ptr< islot_ammo > ammo
Definition: itype.h:835
#define _(msg)
Definition: translations.h:116

References _, itype::ammo, AMMO_DAMAGE_AP, AMMO_DAMAGE_AP_PROPORTIONAL, AMMO_DAMAGE_DISPERSION, AMMO_DAMAGE_PROPORTIONAL, AMMO_DAMAGE_RANGE, AMMO_DAMAGE_RECOIL, AMMO_DAMAGE_VALUE, ammo_data(), ammo_effect_BLACKPOWDER, ammo_effect_INCENDIARY, ammo_effect_NEVER_MISFIRES, ammo_effect_RECYCLED, islot_ammo::ammo_effects, AMMO_FX_BLACKPOWDER, AMMO_FX_CANTMISSFIRE, AMMO_FX_INCENDIARY, AMMO_FX_RECYCLED, ammo_remaining(), AMMO_REMAINING_OR_TYPES, AMMO_SHAPE, ammo_type(), common_ranged_data::damage, damage_instance::damage_units, common_ranged_data::dispersion, damage_instance::empty(), islot_ammo::force_stat_display, get_ranged_armor_mult(), get_ranged_pierce(), info(), insert_separation_line(), is_ammo(), iteminfo::is_decimal, is_gun(), iteminfo::lower_is_better, om_direction::name(), nname(), iteminfo::no_newline, common_ranged_data::range, islot_ammo::recoil, islot_ammo::shape, sign::space, string_format(), iteminfo_query::test(), and damage_instance::total_damage().

Referenced by info().

◆ ammo_remaining()

int item::ammo_remaining ( ) const

Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.

Definition at line 7384 of file item.cpp.

7385{
7386 const item *mag = magazine_current();
7387 if( mag ) {
7388 return mag->ammo_remaining();
7389 }
7390
7391 if( is_tool() || is_gun() ) {
7392 // includes auxiliary gunmods
7394 int power = units::to_kilojoule( get_avatar().get_power_level() );
7395 return power;
7396 }
7397 return charges;
7398 }
7399
7400 if( is_magazine() || is_bandolier() ) {
7401 int res = 0;
7402 for( const item *e : contents.all_items_top() ) {
7403 res += e->charges;
7404 }
7405 return res;
7406 }
7407
7408 return 0;
7409}

References item_contents::all_items_top(), ammo_remaining(), charges, contents, flag_USES_BIONIC_POWER(), get_avatar(), has_flag(), is_bandolier(), is_gun(), is_magazine(), is_tool(), magazine_current(), and units::to_kilojoule().

Referenced by game::add_artifact_dreams(), ammo_consume(), character_funcs::ammo_count_for(), ammo_info(), ammo_remaining(), turret_data::ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_sufficient(), item_funcs::can_be_unloaded(), turret_data::can_reload(), turret_data::can_unload(), firestarter_actor::can_use(), Character::consume_charges(), iuse::cs_lajatang_off(), Character::deactivate_bionic(), display_name(), npc::do_reload(), aim_activity_actor::do_turn(), iuse::ehandcuffs(), iuse::einktabletpc(), fill_with(), ranged::fire_gun(), character_funcs::fmt_wielded_weapon(), iuse::foodperson(), get_remaining_capacity_for_liquid(), getlight_emit(), gun_recoil(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), activity_handlers::hand_crank_do_turn(), Character::has_enough_charges(), ideal_ranged_dps(), vehicle::interact_with(), is_gunmod_compatible(), is_reloadable_helper(), item(), item_action_generator::map_actions_to_items(), Item_modifier::modify(), iuse::multicooker(), iuse::oxytorch(), target_ui::panel_gun_info(), price(), game::process_artifact(), Character::process_items(), relic_funcs::process_recharge(), process_vehicle_items(), item_reload_option::qty(), iuse::radio_on(), avatar_action::reload(), reload(), activity_handlers::repair_item_finish(), item_funcs::shots_remaining(), iuse::tazer2(), tool_info(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse::vibe(), activity_handlers::vibe_do_turn(), wants_to_reload(), wants_to_reload_with(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_required()

int item::ammo_required ( ) const

Quantity of ammunition consumed per usage of tool or with each shot of gun.

Definition at line 7454 of file item.cpp.

7455{
7456 if( is_tool() ) {
7457 return std::max( type->charges_to_use(), 0 );
7458 }
7459
7460 if( is_gun() ) {
7461 if( ammo_types().empty() ) {
7462 return 0;
7463 } else if( has_flag( flag_FIRE_100 ) ) {
7464 return 100;
7465 } else if( has_flag( flag_FIRE_50 ) ) {
7466 return 50;
7467 } else if( has_flag( flag_FIRE_20 ) ) {
7468 return 20;
7469 } else {
7470 return 1;
7471 }
7472 }
7473
7474 return 0;
7475}
static const std::string flag_FIRE_100("FIRE_100")
static const std::string flag_FIRE_50("FIRE_50")
static const std::string flag_FIRE_20("FIRE_20")
int charges_to_use() const
Definition: itype.cpp:110

References ammo_types(), itype::charges_to_use(), flag_FIRE_100(), flag_FIRE_20(), flag_FIRE_50(), has_flag(), is_gun(), is_tool(), and type.

Referenced by character_funcs::ammo_count_for(), turret_data::ammo_options(), ammo_sufficient(), firestarter_actor::can_use(), cauterize_actor::can_use(), Character::consume_charges(), salvage_actor::cut_up(), display_name(), npc::do_reload(), ranged::fire_gun(), mattack::frag(), activity_handlers::game_do_turn(), activatable_inventory_preset::get_denial(), gun_recoil(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), vehicle::interact_with(), activity_handlers::jackhammer_finish(), item_action_generator::map_actions_to_items(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::pickaxe_finish(), iuse::portable_game(), turret_data::prepare_fire(), npc::pretend_fire(), process_tool(), turret_data::query(), activity_handlers::repair_item_finish(), mattack::rifle(), item_funcs::shots_remaining(), mattack::tankgun(), units_sufficient(), inscribe_actor::use(), cauterize_actor::use(), enzlave_actor::use(), wants_to_reload(), and wants_to_reload_with().

◆ ammo_set()

item & item::ammo_set ( const itype_id ammo,
int  qty = -1 
)

Filter setting the ammo for this instance Any existing ammo is removed.

If necessary a magazine is also added.

Parameters
ammospecific type of ammo (must be compatible with item ammo type)
qtymaximum ammo (capped by item capacity) or negative to fill to capacity
Returns
same instance to allow method chaining

Definition at line 595 of file item.cpp.

596{
597 if( qty < 0 ) {
598 // completely fill an integral or existing magazine
600 qty = ammo_capacity();
601
602 // else try to add a magazine using default ammo count property if set
603 } else if( !magazine_default().is_null() ) {
604 item mag( magazine_default() );
605 if( mag.type->magazine->count > 0 ) {
606 qty = mag.type->magazine->count;
607 } else {
608 qty = item( magazine_default() ).ammo_capacity();
609 }
610 }
611 }
612
613 if( qty <= 0 ) {
614 ammo_unset();
615 return *this;
616 }
617
618 // handle reloadable tools and guns with no specific ammo type as special case
619 if( ( ammo.is_null() && ammo_types().empty() ) || is_money() ) {
620 if( ( is_tool() || is_gun() ) && magazine_integral() ) {
621 curammo = nullptr;
622 charges = std::min( qty, ammo_capacity() );
623 }
624 return *this;
625 }
626
627 // check ammo is valid for the item
628 const itype *atype = &*ammo;
629 if( !atype->ammo || !ammo_types().count( atype->ammo->type ) ) {
630 debugmsg( "Tried to set invalid ammo %s[%d] for %s", atype->get_id(), qty, typeId() );
631 return *this;
632 }
633
634 if( is_magazine() ) {
635 ammo_unset();
636 item set_ammo( ammo, calendar::turn, std::min( qty, ammo_capacity() ) );
637 if( has_flag( flag_NO_UNLOAD ) ) {
638 set_ammo.set_flag( "NO_DROP" );
639 set_ammo.set_flag( "IRREMOVABLE" );
640 }
641 put_in( set_ammo );
642
643 } else if( magazine_integral() ) {
644 curammo = atype;
645 charges = std::min( qty, ammo_capacity() );
646
647 } else {
648 if( !magazine_current() ) {
650 if( !mag->magazine ) {
651 debugmsg( "Tried to set ammo %s[%d] without suitable magazine for %s",
652 atype->get_id(), qty, typeId() );
653 return *this;
654 }
655
656 // if default magazine too small fetch instead closest available match
657 if( mag->magazine->capacity < qty ) {
658 // as above call to magazine_default successful can infer minimum one option exists
659 auto iter = type->magazines.find( atype->ammo->type );
660 if( iter == type->magazines.end() ) {
661 debugmsg( "%s doesn't have a magazine for %s",
662 typeId(), ammo );
663 return *this;
664 }
665 std::vector<itype_id> opts( iter->second.begin(), iter->second.end() );
666 std::sort( opts.begin(), opts.end(), []( const itype_id & lhs, const itype_id & rhs ) {
667 return lhs->magazine->capacity < rhs->magazine->capacity;
668 } );
669 mag = opts.back();
670 for( const itype_id &e : opts ) {
671 if( e->magazine->capacity >= qty ) {
672 mag = e;
673 break;
674 }
675 }
676 }
677 put_in( item( mag ) );
678 }
679 magazine_current()->ammo_set( ammo, qty );
680 }
681
682 return *this;
683}
bool is_money() const
Definition: item.cpp:6010
item & ammo_unset()
Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-o...
Definition: item.cpp:685
bool is_null() const
Returns whether this represents the id of the null-object (in which case it's the null-id).
Definition: string_id.h:325
static const std::string flag_NO_UNLOAD("NO_UNLOAD")
std::map< ammotype, std::set< itype_id > > magazines
Magazine types (if any) for each ammo type that can be used to reload this item.
Definition: itype.h:991

References itype::ammo, ammo_capacity(), ammo_set(), ammo_types(), ammo_unset(), charges, count(), curammo, debugmsg, flag_NO_UNLOAD(), itype::get_id(), has_flag(), is_gun(), is_magazine(), is_money(), is_null(), string_id< T >::is_null(), is_tool(), item(), itype::magazine, magazine_current(), magazine_default(), magazine_integral(), itype::magazines, put_in(), set_flag(), calendar::turn, type, and typeId().

Referenced by Character::activate_bionic(), ammo_set(), vehicle_part::ammo_set(), mdeath::broken(), npc::check_toggle_cbm(), crafting::complete_disassemble(), vehicle_part::deserialize(), game::dump_stats(), fill_with(), find_reloadable_cbms(), basecamp::form_crafting_inventory(), gun_info(), npc_ai::gun_value(), activity_handlers::hand_crank_do_turn(), vehicle::interact_with(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), npc::starting_weapon(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), iuse_transform::use(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_sort_name()

std::string item::ammo_sort_name ( ) const

Definition at line 7648 of file item.cpp.

7649{
7650 if( is_magazine() || is_gun() || is_tool() ) {
7651 const std::set<ammotype> &types = ammo_types();
7652 if( !types.empty() ) {
7653 return ammotype( *types.begin() )->name();
7654 }
7655 }
7656 if( is_ammo() ) {
7657 return ammo_type()->name();
7658 }
7659 return "";
7660}
std::string name() const
Definition: ammo.cpp:79

References ammo_type(), ammo_types(), is_ammo(), is_gun(), is_magazine(), is_tool(), and ammunition_type::name().

◆ ammo_sufficient()

bool item::ammo_sufficient ( int  qty = 1) const

Check if sufficient ammo is loaded for given number of uses.

Check if there is enough ammo loaded in a tool for the given number of uses or given number of gun shots. Using this function for this check is preferred because we expect to add support for items consuming multiple ammo types in the future. Users of this function will not need to be refactored when this happens.

Parameters
[in]qtyNumber of uses
Returns
true if ammo sufficient for number of uses is loaded, false otherwise

Definition at line 7477 of file item.cpp.

7478{
7479 return ammo_remaining() >= ammo_required() * qty;
7480}
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7454

References ammo_remaining(), and ammo_required().

Referenced by can_do_activity_there(), iuse::extinguisher(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), iuse::jet_injector(), item_action_generator::map_actions_to_items(), mine_activity(), avatar_action::move(), iuse::pheromone(), iuse::portal(), turret_data::query(), iuse::radiocar(), iuse::radiocaron(), examine_item_menu::rate_action_use(), iuse::rm13armor_off(), iuse::shavekit(), gun_actor::shoot(), iuse::stimpack(), and iuse::teleport().

◆ ammo_type()

ammotype item::ammo_type ( ) const

Ammo type of an ammo item.

Returns
ammotype of ammo item or a null id if the item is not ammo

Definition at line 7590 of file item.cpp.

7591{
7592 if( is_ammo() ) {
7593 return type->ammo->type;
7594 }
7595 return ammotype::NULL_ID();
7596}

References itype::ammo, is_ammo(), string_id< ammunition_type >::NULL_ID(), and type.

Referenced by vehicle::add_item(), ammo_info(), ammo_sort_name(), mdeath::broken(), color_in_inventory(), detonate(), character_funcs::find_ammo_helper(), character_funcs::get_ammo_items(), item_reload_option::qty(), reload(), and npc::value().

◆ ammo_types()

const std::set< ammotype > & item::ammo_types ( bool  conversion = true) const

Set of ammo types (ammunition_type) used by item.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
empty set if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7567 of file item.cpp.

7568{
7569 if( conversion ) {
7570 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7571 for( const item *e : mods ) {
7572 if( !e->type->mod->ammo_modifier.empty() ) {
7573 return e->type->mod->ammo_modifier;
7574 }
7575 }
7576 }
7577
7578 if( is_gun() ) {
7579 return type->gun->ammo;
7580 } else if( is_tool() ) {
7581 return type->tool->ammo_id;
7582 } else if( is_magazine() ) {
7583 return type->magazine->type;
7584 }
7585
7586 static std::set<ammotype> atypes = {};
7587 return atypes;
7588}

References itype::gun, gunmods(), is_gun(), is_magazine(), is_tool(), itype::magazine, itype::tool, toolmods(), and type.

Referenced by vehicle::add_item(), allow_crafting_component(), ammo_default(), turret_data::ammo_options(), ammo_required(), ammo_set(), ammo_sort_name(), mdeath::broken(), item_funcs::can_be_unloaded(), color_in_inventory(), common_ammo_default(), craft_has_charges(), display_name(), avatar_action::fire_wielded_weapon(), get_quality(), avatar_funcs::gunmod_add(), vehicle_part::is_battery(), is_gunmod_compatible(), is_money(), is_reloadable(), is_reloadable_helper(), item(), magazine_compatible(), magazine_default(), magazine_info(), Item_modifier::modify(), price(), relic_funcs::process_recharge_entry(), character_funcs::select_ammo(), set_countdown(), tool_info(), avatar_funcs::unload_item(), npc::value(), and weight().

◆ ammo_unset()

item & item::ammo_unset ( )

Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present.

Definition at line 685 of file item.cpp.

686{
687 if( !is_tool() && !is_gun() && !is_magazine() ) {
688 // do nothing
689 } else if( is_magazine() ) {
691 } else if( magazine_integral() ) {
692 curammo = nullptr;
693 charges = 0;
694 } else if( magazine_current() ) {
696 }
697
698 return *this;
699}

References ammo_unset(), charges, item_contents::clear_items(), contents, curammo, is_gun(), is_magazine(), is_tool(), magazine_current(), and magazine_integral().

Referenced by ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), iuse::ehandcuffs(), emit_radio_signal(), npc_ai::gun_value(), and ammobelt_actor::use().

◆ animal_armor_info()

void item::animal_armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2737 of file item.cpp.

2739{
2740 if( !is_pet_armor() ) {
2741 return;
2742 }
2743
2744 const std::string space = " ";
2745
2746 int converted_storage_scale = 0;
2747 const double converted_storage = round_up( convert_volume( get_storage().value(),
2748 &converted_storage_scale ), 2 );
2749 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2750 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2751 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2752 string_format( "<num> %s", volume_units_abbr() ),
2753 f, converted_storage ) );
2754 }
2755
2756 // Whatever the last entry was, we want a newline at this point
2757 info.back().bNewLine = true;
2758
2759 armor_protection_info( info, parts, batch, debug );
2760}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
units::volume get_storage() const
Returns the storage amount (islot_armor::storage) that this item provides when worn.
Definition: item.cpp:5742
void armor_protection_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2511
bool is_pet_armor(bool on_pet=false) const
Definition: item.cpp:6708
constexpr auto debug
Definition: options.cpp:156
Value and metadata for one property of an item.
Definition: item.h:107
flags
Definition: item.h:142
@ no_flags
Definition: item.h:143
const char * volume_units_abbr()
Create an abbreviated units label for a volume value.
double convert_volume(int volume)
Convert volume from ml to units defined by user.

References _, armor_protection_info(), ARMOR_STORAGE, convert_volume(), debug, get_storage(), info(), iteminfo::is_decimal, is_pet_armor(), iteminfo::no_flags, round_up(), sign::space, string_format(), iteminfo_query::test(), and volume_units_abbr().

Referenced by info().

◆ armor_fit_info()

void item::armor_fit_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2762 of file item.cpp.

2764{
2765 if( !is_armor() ) {
2766 return;
2767 }
2768
2769 avatar &you = get_avatar();
2770 int encumbrance = get_encumber( you );
2771 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2772
2775 info.push_back( iteminfo( "DESCRIPTION",
2776 _( "* This item can be <info>worn with a "
2777 "helmet</info>." ) ) );
2778 }
2779
2781 switch( sizing_level ) {
2783 if( has_flag( flag_FIT ) ) {
2784 info.emplace_back( "DESCRIPTION",
2785 _( "* This clothing <info>fits</info> you perfectly." ) );
2786 }
2787 break;
2789 if( has_flag( flag_FIT ) ) {
2790 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2791 "your large frame perfectly." ) );
2792 }
2793 break;
2795 if( has_flag( flag_FIT ) ) {
2796 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2797 "your small frame perfectly." ) );
2798 }
2799 break;
2801 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>oversized</bad> "
2802 "and does <bad>not fit</bad> you." ) );
2803 break;
2805 info.emplace_back( "DESCRIPTION",
2806 _( "* This clothing is hilariously <bad>oversized</bad> "
2807 "and does <bad>not fit</bad> your <info>abnormally "
2808 "small mutated anatomy</info>." ) );
2809 break;
2811 info.emplace_back( "DESCRIPTION",
2812 _( "* This clothing is <bad>normal sized</bad> and does "
2813 "<bad>not fit</info> your <info>abnormally large "
2814 "mutated anatomy</info>." ) );
2815 break;
2817 info.emplace_back( "DESCRIPTION",
2818 _( "* This clothing is <bad>normal sized</bad> and does "
2819 "<bad>not fit</bad> your <info>abnormally small "
2820 "mutated anatomy</info>." ) );
2821 break;
2823 info.emplace_back( "DESCRIPTION",
2824 _( "* This clothing is hilariously <bad>undersized</bad> "
2825 "and does <bad>not fit</bad> your <info>abnormally "
2826 "large mutated anatomy</info>." ) );
2827 break;
2829 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>undersized</bad> "
2830 "and does <bad>not fit</bad> you." ) );
2831 break;
2832 default:
2833 break;
2834 }
2835 }
2836
2838 if( has_flag( flag_VARSIZE ) ) {
2839 std::string resize_str;
2840 if( has_flag( flag_FIT ) ) {
2841 switch( sizing_level ) {
2843 resize_str = _( "<info>can be upsized</info>" );
2844 break;
2846 resize_str = _( "<info>can be downsized</info>" );
2847 break;
2850 resize_str = _( "<bad>can not be downsized</bad>" );
2851 break;
2854 resize_str = _( "<bad>can not be upsized</bad>" );
2855 break;
2856 default:
2857 break;
2858 }
2859 if( !resize_str.empty() ) {
2860 std::string info_str = string_format( _( "* This clothing %s." ), resize_str );
2861 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2862 }
2863 } else {
2864 switch( sizing_level ) {
2866 resize_str = _( " and <info>upsized</info>" );
2867 break;
2869 resize_str = _( " and <info>downsized</info>" );
2870 break;
2873 resize_str = _( " but <bad>not downsized</bad>" );
2874 break;
2877 resize_str = _( " but <bad>not upsized</bad>" );
2878 break;
2879 default:
2880 break;
2881 }
2882 std::string info_str = string_format( _( "* This clothing <info>can be "
2883 "refitted</info>%s." ), resize_str );
2884 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2885 }
2886 } else {
2887 info.emplace_back( "DESCRIPTION", _( "* This clothing <bad>can not be refitted, "
2888 "upsized, or downsized</bad>." ) );
2889 }
2890 }
2891
2893 info.push_back( iteminfo( "DESCRIPTION",
2894 _( "* This item can be worn on <info>either side</info> of "
2895 "the body." ) ) );
2896 }
2897 if( ( is_power_armor() ) &&
2901 info.push_back( iteminfo( "DESCRIPTION",
2902 _( "* When worn with a power armor suit, it will "
2903 "<good>fully protect</good> you from "
2904 "<info>radiation</info>." ) ) );
2905 } else if( has_flag( flag_POWERARMOR_EXO ) ) {
2906 info.push_back( iteminfo( "DESCRIPTION",
2907 _( "* When worn with a power armor helmet, it will "
2908 "<good>fully protect</good> you from " "<info>radiation</info>." ) ) );
2909 }
2910 }
2911 }
2913 info.push_back( iteminfo( "DESCRIPTION",
2914 string_format( _( "* The film strip on the badge is %s." ),
2916 }
2917}
@ bp_head
Definition: bodypart.h:43
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:807
int irradiation
Definition: item.h:2217
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5796
sizing
Definition: item.h:2136
@ small_sized_small_char
@ human_sized_human_char
@ small_sized_human_char
@ human_sized_small_char
bool is_armor() const
Definition: item.cpp:6714
sizing get_sizing(const Character &, bool) const
Definition: item.cpp:1182
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5802
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:748
static const std::string flag_FIT("FIT")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const itype_id itype_rad_badge("rad_badge")
static const std::string flag_VARSIZE("VARSIZE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
std::string rad_badge_color(const int rad)
Definition: item.cpp:294
@ DESCRIPTION_FLAGS_POWERARMOR
@ DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT
@ DESCRIPTION_FLAGS_HELMETCOMPAT

References _, big_sized_big_char, big_sized_human_char, big_sized_small_char, bp_head, covers(), DESCRIPTION_FLAGS_FITS, DESCRIPTION_FLAGS_HELMETCOMPAT, DESCRIPTION_FLAGS_POWERARMOR, DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT, DESCRIPTION_FLAGS_SIDED, DESCRIPTION_FLAGS_VARSIZE, DESCRIPTION_IRRADIATION, flag_FIT(), flag_HELMET_COMPAT(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_VARSIZE(), get_avatar(), get_encumber(), get_sizing(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, info(), irradiation, is_armor(), is_power_armor(), is_sided(), itype_rad_badge, rad_badge_color(), small_sized_big_char, small_sized_human_char, small_sized_small_char, string_format(), iteminfo_query::test(), and typeId().

Referenced by final_info().

◆ armor_info()

void item::armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2554 of file item.cpp.

2556{
2557 if( !is_armor() ) {
2558 return;
2559 }
2560
2561 avatar &you = get_avatar();
2562 int encumbrance = get_encumber( you );
2563 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2564 const std::string space = " ";
2565 body_part_set covered_parts = get_covered_body_parts();
2566 bool covers_anything = covered_parts.any();
2567
2568 if( parts->test( iteminfo_parts::ARMOR_BODYPARTS ) ) {
2570 std::string coverage = _( "<bold>Covers</bold>: " );
2571 if( covers( bp_head ) ) {
2572 coverage += _( "The <info>head</info>. " );
2573 }
2574 if( covers( bp_eyes ) ) {
2575 coverage += _( "The <info>eyes</info>. " );
2576 }
2577 if( covers( bp_mouth ) ) {
2578 coverage += _( "The <info>mouth</info>. " );
2579 }
2580 if( covers( bp_torso ) ) {
2581 coverage += _( "The <info>torso</info>. " );
2582 }
2583
2584 if( is_sided() && ( covers( bp_arm_l ) || covers( bp_arm_r ) ) ) {
2585 coverage += _( "Either <info>arm</info>. " );
2586 } else if( covers( bp_arm_l ) && covers( bp_arm_r ) ) {
2587 coverage += _( "The <info>arms</info>. " );
2588 } else if( covers( bp_arm_l ) ) {
2589 coverage += _( "The <info>left arm</info>. " );
2590 } else if( covers( bp_arm_r ) ) {
2591 coverage += _( "The <info>right arm</info>. " );
2592 }
2593
2594 if( is_sided() && ( covers( bp_hand_l ) || covers( bp_hand_r ) ) ) {
2595 coverage += _( "Either <info>hand</info>. " );
2596 } else if( covers( bp_hand_l ) && covers( bp_hand_r ) ) {
2597 coverage += _( "The <info>hands</info>. " );
2598 } else if( covers( bp_hand_l ) ) {
2599 coverage += _( "The <info>left hand</info>. " );
2600 } else if( covers( bp_hand_r ) ) {
2601 coverage += _( "The <info>right hand</info>. " );
2602 }
2603
2604 if( is_sided() && ( covers( bp_leg_l ) || covers( bp_leg_r ) ) ) {
2605 coverage += _( "Either <info>leg</info>. " );
2606 } else if( covers( bp_leg_l ) && covers( bp_leg_r ) ) {
2607 coverage += _( "The <info>legs</info>. " );
2608 } else if( covers( bp_leg_l ) ) {
2609 coverage += _( "The <info>left leg</info>. " );
2610 } else if( covers( bp_leg_r ) ) {
2611 coverage += _( "The <info>right leg</info>. " );
2612 }
2613
2614 if( is_sided() && ( covers( bp_foot_l ) || covers( bp_foot_r ) ) ) {
2615 coverage += _( "Either <info>foot</info>. " );
2616 } else if( covers( bp_foot_l ) && covers( bp_foot_r ) ) {
2617 coverage += _( "The <info>feet</info>. " );
2618 } else if( covers( bp_foot_l ) ) {
2619 coverage += _( "The <info>left foot</info>. " );
2620 } else if( covers( bp_foot_r ) ) {
2621 coverage += _( "The <info>right foot</info>. " );
2622 }
2623
2624 if( !covers_anything ) {
2625 coverage += _( "<info>Nothing</info>." );
2626 }
2627
2628 info.push_back( iteminfo( "ARMOR", coverage ) );
2629 }
2630
2631 if( parts->test( iteminfo_parts::ARMOR_LAYER ) && covers_anything ) {
2632 std::string layering = _( "Layer: " );
2633 if( has_flag( flag_PERSONAL ) ) {
2634 layering += _( "<stat>Personal aura</stat>. " );
2635 } else if( has_flag( flag_SKINTIGHT ) ) {
2636 layering += _( "<stat>Close to skin</stat>. " );
2637 } else if( has_flag( flag_BELTED ) ) {
2638 layering += _( "<stat>Strapped</stat>. " );
2639 } else if( has_flag( flag_OUTER ) ) {
2640 layering += _( "<stat>Outer</stat>. " );
2641 } else if( has_flag( flag_WAIST ) ) {
2642 layering += _( "<stat>Waist</stat>. " );
2643 } else if( has_flag( flag_AURA ) ) {
2644 layering += _( "<stat>Outer aura</stat>. " );
2645 } else {
2646 layering += _( "<stat>Normal</stat>. " );
2647 }
2648
2649 info.push_back( iteminfo( "ARMOR", layering ) );
2650 }
2651
2652 if( parts->test( iteminfo_parts::ARMOR_COVERAGE ) && covers_anything ) {
2653 info.push_back( iteminfo( "ARMOR", _( "Coverage: " ), "<num>%",
2655 }
2656 if( parts->test( iteminfo_parts::ARMOR_WARMTH ) && covers_anything ) {
2657 info.push_back( iteminfo( "ARMOR", space + _( "Warmth: " ), get_warmth() ) );
2658 }
2659
2661
2662 if( parts->test( iteminfo_parts::ARMOR_ENCUMBRANCE ) && covers_anything ) {
2663 std::string format;
2664 if( has_flag( flag_FIT ) ) {
2665 format = _( "<num> <info>(fits)</info>" );
2666 } else if( has_flag( flag_VARSIZE ) && encumbrance ) {
2667 format = _( "<num> <bad>(poor fit)</bad>" );
2668 }
2669
2670 //If we have the wrong size, we do not fit so alert the player
2671 if( sizing_level == sizing::human_sized_small_char ) {
2672 format = _( "<num> <bad>(too big)</bad>" );
2673 } else if( sizing_level == sizing::big_sized_small_char ) {
2674 format = _( "<num> <bad>(huge!)</bad>" );
2675 } else if( sizing_level == sizing::small_sized_human_char ||
2676 sizing_level == sizing::human_sized_big_char ) {
2677 format = _( "<num> <bad>(too small)</bad>" );
2678 } else if( sizing_level == sizing::small_sized_big_char ) {
2679 format = _( "<num> <bad>(tiny!)</bad>" );
2680 }
2681
2682 info.push_back( iteminfo( "ARMOR", _( "<bold>Encumbrance</bold>: " ), format,
2684 encumbrance ) );
2685 if( !type->rigid ) {
2686 const int encumbrance_when_full =
2688 info.push_back( iteminfo( "ARMOR", space + _( "Encumbrance when full: " ), "",
2690 encumbrance_when_full ) );
2691 }
2692 }
2693
2694 int converted_storage_scale = 0;
2695 const double converted_storage = round_up( convert_volume( get_storage().value(),
2696 &converted_storage_scale ), 2 );
2697 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2698 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2699 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2700 string_format( "<num> %s", volume_units_abbr() ),
2701 f, converted_storage ) );
2702 }
2703
2704 // Whatever the last entry was, we want a newline at this point
2705 info.back().bNewLine = true;
2706
2707 if( covers_anything ) {
2708 armor_protection_info( info, parts, batch, debug );
2709 }
2710
2711 const units::mass weight_bonus = get_weight_capacity_bonus();
2712 const float weight_modif = get_weight_capacity_modifier();
2713 if( weight_modif != 1 ) {
2714 std::string modifier;
2715 if( weight_modif < 1 ) {
2716 modifier = "<num><bad>x</bad>";
2717 } else {
2718 modifier = "<num><color_light_green>x</color>";
2719 }
2720 info.push_back( iteminfo( "ARMOR",
2721 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
2722 iteminfo::no_newline | iteminfo::is_decimal, weight_modif ) );
2723 }
2724 if( weight_bonus != 0_gram ) {
2725 std::string bonus;
2726 if( weight_bonus < 0_gram ) {
2727 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
2728 } else {
2729 bonus = string_format( "<num> <color_light_green> %s</color>", weight_units() );
2730 }
2731 info.push_back( iteminfo( "ARMOR", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
2733 convert_weight( weight_bonus ) ) );
2734 }
2735}
@ bp_foot_l
Definition: bodypart.h:52
@ bp_leg_r
Definition: bodypart.h:51
@ bp_eyes
Definition: bodypart.h:44
@ bp_hand_l
Definition: bodypart.h:48
@ bp_arm_l
Definition: bodypart.h:46
@ bp_leg_l
Definition: bodypart.h:50
@ bp_hand_r
Definition: bodypart.h:49
@ bp_torso
Definition: bodypart.h:42
@ bp_mouth
Definition: bodypart.h:45
@ bp_foot_r
Definition: bodypart.h:53
@ bp_arm_r
Definition: bodypart.h:47
bool any() const
Definition: bodypart.h:265
units::volume get_total_capacity() const
It returns the maximum volume of any contents, including liquids, ammo, magazines,...
Definition: item.cpp:8410
int get_encumber_when_containing(const Character &, const units::volume &contents_volume) const
Returns the encumbrance value that this item has when worn by given player, when containing a particu...
Definition: item.cpp:5830
units::mass get_weight_capacity_bonus() const
Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides whe...
Definition: item.cpp:5764
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:758
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5928
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5910
float get_weight_capacity_modifier() const
Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides ...
Definition: item.cpp:5755
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
\rst Formats arguments and returns the result as a string.
Definition: fmtlib_core.h:2316
static const std::string flag_WAIST("WAIST")
static const std::string flag_BELTED("BELTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_OUTER("OUTER")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
bool rigid
Definition: itype.h:962
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References _, body_part_set::any(), ARMOR_BODYPARTS, ARMOR_COVERAGE, ARMOR_ENCUMBRANCE, ARMOR_LAYER, armor_protection_info(), ARMOR_STORAGE, ARMOR_WARMTH, big_sized_small_char, bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, convert_volume(), convert_weight(), covers(), debug, flag_AURA(), flag_BELTED(), flag_FIT(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_VARSIZE(), flag_WAIST(), format(), get_avatar(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_sizing(), get_storage(), get_total_capacity(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), has_flag(), human_sized_big_char, human_sized_small_char, info(), insert_separation_line(), is_armor(), iteminfo::is_decimal, is_sided(), iteminfo::lower_is_better, iteminfo::no_flags, iteminfo::no_newline, itype::rigid, round_up(), small_sized_big_char, small_sized_human_char, sign::space, string_format(), iteminfo_query::test(), type, volume_units_abbr(), and weight_units().

Referenced by info().

◆ armor_protection_info()

void item::armor_protection_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2511 of file item.cpp.

2514{
2515 if( !is_armor() && !is_pet_armor() ) {
2516 return;
2517 }
2518
2519 const std::string space = " ";
2520
2521 if( parts->test( iteminfo_parts::ARMOR_PROTECTION ) ) {
2522 info.push_back( iteminfo( "ARMOR", _( "<bold>Protection</bold>: Bash: " ), "",
2524 info.push_back( iteminfo( "ARMOR", space + _( "Cut: " ), "", iteminfo::no_newline, cut_resist() ) );
2525 info.push_back( iteminfo( "ARMOR", space + _( "Ballistic: " ), bullet_resist() ) );
2526 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2528 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2530 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2531 get_base_env_resist( *this ) ) );
2532 if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
2533 info.push_back( iteminfo( "ARMOR",
2534 _( "<bold>Protection when active</bold>: " ) ) );
2535 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2538 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2541 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2543 }
2544
2545 if( damage() > 0 ) {
2546 info.push_back( iteminfo( "ARMOR",
2547 _( "Protection values are <bad>reduced by damage</bad> and "
2548 "you may be able to <info>improve them by repairing this "
2549 "item</info>." ) ) );
2550 }
2551 }
2552}
int bash_resist(bool to_self=false) const
Definition: item.cpp:6041
int fire_resist(bool to_self=false, int base_env_resist=0) const
Definition: item.cpp:6171
int acid_resist(bool to_self=false, int base_env_resist=0) const
Resistance against different damage types (damage_type).
Definition: item.cpp:6137
int bullet_resist(bool to_self=false) const
Definition: item.cpp:6108
int get_base_env_resist_w_filter() const
Returns the base resistance to environmental effects if an item (for example a gas mask) requires a g...
Definition: item.cpp:5787
int cut_resist(bool to_self=false) const
Definition: item.cpp:6069
int damage() const
How much damage has the item sustained?
Definition: item.cpp:701
static int get_base_env_resist(const item &it)
Definition: item.cpp:1225
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:161

References _, acid_resist(), ARMOR_PROTECTION, bash_resist(), bullet_resist(), itype::can_use(), cut_resist(), damage(), fire_resist(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), info(), is_armor(), is_pet_armor(), iteminfo::no_newline, sign::space, iteminfo_query::test(), and type.

Referenced by animal_armor_info(), and armor_info().

◆ attack_cost()

int item::attack_cost ( ) const

Base number of moves (Creature::moves) that a single melee attack with this items takes.

The actual time depends heavily on the attacker, see melee.cpp.

Definition at line 5208 of file item.cpp.

5209{
5210 int base = 65 + ( volume() / 62.5_ml + weight() / 60_gram ) / count();
5212 return std::max( 0, base + bonus );
5213}
double bonus_from_enchantments_wielded(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantment...
Definition: item.cpp:7016
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4985
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:5131

References bonus_from_enchantments_wielded(), count(), enchant_vals::ITEM_ATTACK_COST, volume(), and weight().

Referenced by Character::attack_cost(), combat_info(), Character::melee_attack(), npc::move_to(), smash(), and ranged::throw_cost().

◆ average_dps()

double item::average_dps ( const player guy) const

return the average dps of the weapon against evaluation monsters

Definition at line 1453 of file item.cpp.

1454{
1455 double dmg_count = 0.0;
1456 const std::map<std::string, double> &dps_data = dps( false, true, guy );
1457 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
1458 dmg_count += dps_entry.second;
1459 }
1460 return dmg_count / dps_data.size();
1461}
std::map< std::string, double > dps(bool for_display, bool for_calc, const player &guy) const
calculate effective dps against a stock set of monsters.
Definition: item.cpp:1433

References dps().

Referenced by npc_ai::melee_value().

◆ base_damage_melee()

damage_instance item::base_damage_melee ( ) const

All damage types this item deals when used in melee (no skill modifiers etc.

applied).

Definition at line 5271 of file item.cpp.

5272{
5273 // TODO: Caching
5275 for( size_t i = DT_NULL + 1; i < NUM_DT; i++ ) {
5276 damage_type dt = static_cast<damage_type>( i );
5277 int dam = damage_melee( dt );
5278 if( dam > 0 ) {
5279 ret.add_damage( dt, dam );
5280 }
5281 }
5282
5283 return ret;
5284}
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5215
damage_type
Definition: damage.h:20
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32

References damage_melee(), DT_NULL, NUM_DT, and cata::hash64_detail::ret.

◆ base_damage_thrown()

damage_instance item::base_damage_thrown ( ) const

All damage types this item deals when thrown (no skill modifiers etc.

applied).

Definition at line 5286 of file item.cpp.

5287{
5288 // TODO: Create a separate cache for individual items (for modifiers like diamond etc.)
5289 return type->thrown_damage;
5290}
damage_instance thrown_damage
Base damage output when thrown.
Definition: itype.h:967

References itype::thrown_damage, and type.

Referenced by ranged::throw_item().

◆ base_volume()

units::volume item::base_volume ( ) const

Simplified, faster volume check for when processing time is important and exact volume is not.

NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Definition at line 5103 of file item.cpp.

5104{
5105 if( is_null() ) {
5106 return 0_ml;
5107 }
5108 if( is_corpse() ) {
5109 return corpse_volume( corpse );
5110 }
5111
5112 if( is_craft() ) {
5113 units::volume ret = 0_ml;
5114 for( const item &it : components ) {
5115 ret += it.base_volume();
5116 }
5117 return ret;
5118 }
5119
5120 if( count_by_charges() ) {
5121 if( type->volume % type->stack_size == 0_ml ) {
5122 return type->volume / type->stack_size;
5123 } else {
5124 return type->volume / type->stack_size + 1_ml;
5125 }
5126 }
5127
5128 return type->volume;
5129}
bool count_by_charges() const
Definition: item.cpp:6015
units::volume corpse_volume(const mtype *corpse) const
Volume check for corpses, helper for base_volume().
Definition: item.cpp:5081
bool is_craft() const
Definition: item.cpp:6933
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6630
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:953
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:945

References components, corpse, corpse_volume(), count_by_charges(), is_corpse(), is_craft(), is_null(), cata::hash64_detail::ret, itype::stack_size, type, and itype::volume.

Referenced by burn(), flammable(), and simulate_burn().

◆ bash_resist()

int item::bash_resist ( bool  to_self = false) const

Definition at line 6041 of file item.cpp.

6042{
6043 if( is_null() ) {
6044 return 0;
6045 }
6046
6047 float resist = 0;
6049 int eff_thickness = 1;
6050
6051 // base resistance
6052 // Don't give reinforced items +armor, just more resistance to ripping
6053 const int dmg = damage_level( 4 );
6054 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6055 eff_thickness = std::max( 1, get_thickness() - eff_damage );
6056
6057 const std::vector<const material_type *> mat_types = made_of_types();
6058 if( !mat_types.empty() ) {
6059 for( const material_type *mat : mat_types ) {
6060 resist += mat->bash_resist();
6061 }
6062 // Average based on number of materials.
6063 resist /= mat_types.size();
6064 }
6065
6066 return std::lround( ( resist * eff_thickness ) + mod );
6067}
int get_thickness() const
Returns the islot_armor::thickness value, or 0 for non-armor.
Definition: item.cpp:5919
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:706
@ clothing_mod_type_bash
Definition: clothing_mod.h:19
STL namespace.

References clothing_mod_type_bash, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ basic_info()

void item::basic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1463 of file item.cpp.

1465{
1467 info.emplace_back( "BASE", string_format( _( "<stat>Origin: %s</stat>" ),
1468 enumerate_as_string( type->src.begin(),
1469 type->src.end(), []( const std::pair<itype_id, mod_id> &source ) {
1470 return string_format( "'%s'", source.second->name() );
1473 }
1475 info.emplace_back( "BASE", colorize( string_format( "[%s]", type->get_id() ), c_light_blue ) );
1477 }
1478
1479 const std::string space = " ";
1480 if( parts->test( iteminfo_parts::BASE_MATERIAL ) ) {
1481 const std::vector<const material_type *> mat_types = made_of_types();
1482 if( !mat_types.empty() ) {
1483 const std::string material_list = enumerate_as_string( mat_types.begin(), mat_types.end(),
1484 []( const material_type * material ) {
1485 return string_format( "<stat>%s</stat>", material->name() );
1487 info.push_back( iteminfo( "BASE", string_format( _( "Material: %s" ), material_list ) ) );
1488 }
1489 }
1490 if( parts->test( iteminfo_parts::BASE_VOLUME ) ) {
1491 int converted_volume_scale = 0;
1492 const double converted_volume = round_up( convert_volume( volume().value(),
1493 &converted_volume_scale ) * batch, 3 );
1495 if( converted_volume_scale != 0 ) {
1497 }
1498 info.push_back( iteminfo( "BASE", _( "Volume: " ),
1499 string_format( "<num> %s", volume_units_abbr() ),
1500 f, converted_volume ) );
1501 }
1502 if( parts->test( iteminfo_parts::BASE_WEIGHT ) ) {
1503 info.push_back( iteminfo( "BASE", space + _( "Weight: " ),
1504 string_format( "<num> %s", weight_units() ),
1506 convert_weight( weight() ) * batch ) );
1507 }
1508 if( !owner.is_null() ) {
1509 info.push_back( iteminfo( "BASE", string_format( _( "Owner: %s" ),
1510 _( get_owner_name() ) ) ) );
1511 }
1512 if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
1513 info.push_back( iteminfo( "BASE", _( "Category: " ),
1514 "<header>" + get_category().name() + "</header>" ) );
1515 }
1516 if( !type->weapon_category.empty() && parts->test( iteminfo_parts::WEAPON_CATEGORY ) ) {
1517 const std::string weapon_categories = enumerate_as_string( type->weapon_category.begin(),
1518 type->weapon_category.end(), [&]( const weapon_category_id & elem ) {
1519 return elem->name().translated();
1521 info.push_back( iteminfo( "BASE", _( "Weapon Category: " ),
1522 "<header>" + weapon_categories + "</header>" ) );
1523 }
1524
1525 if( parts->test( iteminfo_parts::DESCRIPTION ) ) {
1527 const std::map<std::string, std::string>::const_iterator idescription =
1528 item_vars.find( "description" );
1529 const std::optional<translation> snippet = SNIPPET.get_snippet_by_id( snip_id );
1530 if( snippet.has_value() ) {
1531 // Just use the dynamic description
1532 info.push_back( iteminfo( "DESCRIPTION", snippet.value().translated() ) );
1533 } else if( idescription != item_vars.end() ) {
1534 info.push_back( iteminfo( "DESCRIPTION", idescription->second ) );
1535 } else {
1536 if( has_flag( "MAGIC_FOCUS" ) ) {
1537 info.push_back( iteminfo( "DESCRIPTION",
1538 _( "This item is a <info>magical focus</info>. "
1539 "You can cast spells with it in your hand." ) ) );
1540 }
1541 if( is_craft() ) {
1542 const std::string desc = _( "This is an in progress %s. "
1543 "It is %d percent complete." );
1544 const int percent_progress = item_counter / 100000;
1545 info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
1546 craft_data_->making->result_name(),
1547 percent_progress ) ) );
1548 } else {
1549 info.push_back( iteminfo( "DESCRIPTION", type->description.translated() ) );
1550 }
1551 }
1553 }
1554
1556
1557 if( parts->test( iteminfo_parts::BASE_REQUIREMENTS ) ) {
1558 // Display any minimal stat or skill requirements for the item
1559 std::vector<std::string> req;
1560 if( get_min_str() > 0 ) {
1561 avatar &viewer = get_avatar();
1562 if( has_flag( flag_STR_DRAW ) && ranged::get_str_draw_penalty( *this, viewer ) < 1.0f ) {
1563 if( ranged::get_str_draw_penalty( *this, viewer ) < 0.5f ) {
1564 req.push_back( string_format( _( "%s %d <color_magenta>(Can't use!)</color>" ), _( "strength" ),
1565 get_min_str() ) );
1566 } else if( ranged::get_str_draw_penalty( *this, viewer ) < 0.75f ) {
1567 req.push_back( string_format( "%s %d <color_red>(Damage/Range 0.5x, Dispersion 2.0x)</color>",
1568 _( "strength" ), get_min_str() ) );
1569 } else {
1570 req.push_back( string_format( "%s %d <color_yellow>(Damage/Range 0.75x)</color>", _( "strength" ),
1571 get_min_str() ) );
1572 }
1573 } else {
1574 req.push_back( string_format( "%s %d", _( "strength" ), get_min_str() ) );
1575 }
1576 }
1577 if( type->min_dex > 0 ) {
1578 req.push_back( string_format( "%s %d", _( "dexterity" ), type->min_dex ) );
1579 }
1580 if( type->min_int > 0 ) {
1581 req.push_back( string_format( "%s %d", _( "intelligence" ), type->min_int ) );
1582 }
1583 if( type->min_per > 0 ) {
1584 req.push_back( string_format( "%s %d", _( "perception" ), type->min_per ) );
1585 }
1586 for( const std::pair<const skill_id, int> sk : sorted_lex( type->min_skills ) ) {
1587 req.push_back( string_format( "%s %d", skill_id( sk.first )->name(), sk.second ) );
1588 }
1589 if( !req.empty() ) {
1590 info.emplace_back( "BASE", _( "<bold>Minimum requirements</bold>:" ) );
1591 info.emplace_back( "BASE", enumerate_as_string( req ) );
1593 }
1594 }
1595
1596 if( has_var( "contained_name" ) && parts->test( iteminfo_parts::BASE_CONTENTS ) ) {
1597 info.push_back( iteminfo( "BASE", string_format( _( "Contains: %s" ),
1598 get_var( "contained_name" ) ) ) );
1599 }
1600 if( count_by_charges() && !is_food() && !is_medication() &&
1601 parts->test( iteminfo_parts::BASE_AMOUNT ) ) {
1602 info.push_back( iteminfo( "BASE", _( "Amount: " ), "<num>", iteminfo::no_flags,
1603 charges * batch ) );
1604 }
1605 if( debug && parts->test( iteminfo_parts::BASE_DEBUG ) ) {
1606 if( g != nullptr ) {
1607 info.push_back( iteminfo( "BASE", string_format( "itype_id: %s",
1608 typeId().c_str() ) ) );
1609 info.push_back( iteminfo( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
1610 to_hours<int>( age() ) ) );
1611 info.push_back( iteminfo( "BASE", _( "charges: " ), "", iteminfo::lower_is_better,
1612 charges ) );
1613 info.push_back( iteminfo( "BASE", _( "damage: " ), "", iteminfo::lower_is_better,
1614 damage_ ) );
1615 info.push_back( iteminfo( "BASE", _( "active: " ), "", iteminfo::lower_is_better,
1616 active ) );
1617 info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better,
1618 burnt ) );
1619 const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none );
1620 info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) );
1621 for( auto const &imap : item_vars ) {
1622 info.push_back( iteminfo( "BASE",
1623 string_format( _( "item var: %s, %s" ), imap.first,
1624 imap.second ) ) );
1625 }
1626
1627 const item *food = get_food();
1628 if( food && food->goes_bad() ) {
1629 info.push_back( iteminfo( "BASE", _( "age (turns): " ),
1631 to_turns<int>( food->age() ) ) );
1632 info.push_back( iteminfo( "BASE", _( "rot (turns): " ),
1634 to_turns<int>( food->rot ) ) );
1635 info.push_back( iteminfo( "BASE", space + _( "max rot (turns): " ),
1637 to_turns<int>( food->get_shelf_life() ) ) );
1638 info.push_back( iteminfo( "BASE", _( "last rot: " ),
1640 to_turn<int>( food->last_rot_check ) ) );
1641 }
1642 }
1643 }
1644}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1035
int burnt
Definition: item.h:2213
int get_min_str() const
Definition: item.cpp:10051
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1080
time_duration age() const
Definition: item.cpp:10012
time_duration rot
Accumulated rot, expressed as time the item has been in standard temperature.
Definition: item.h:2233
faction_id owner
Definition: item.h:2239
bool is_medication() const
Definition: item.cpp:6608
time_duration get_shelf_life() const
Get the shelf life of the item.
Definition: item.cpp:5546
int damage_
Definition: item.h:2242
item * get_food()
Definition: item.cpp:6652
const item_category & get_category() const
Definition: item.cpp:8692
FlagsSetType item_tags
Definition: item.h:2177
std::string get_owner_name() const
Definition: item.cpp:1266
std::optional< translation > get_snippet_by_id(const snippet_id &id) const
Returns the snippet referenced by the id, or std::nullopt if there is no snippet with such id.
std::string translated(int num=1) const
Returns raw string if no translation is needed, otherwise returns the translated string.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
#define c_light_blue
Definition: color.h:29
std::unique_ptr< game > g
Definition: game.cpp:285
static const std::string flag_STR_DRAW("STR_DRAW")
std::vector< material_type > material_list
Definition: material.h:23
float get_str_draw_penalty(const item &it, const Character &p)
Penalties potentially incurred by STR_DRAW weapons.
Definition: ranged.cpp:1020
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
std::vector< std::pair< K, V > > sorted_lex(Col col)
Returns vector sorted by lexicographic order of string_id.
@ is_three_decimal
Print as decimal with three points of precision.
Definition: item.h:145
int min_dex
Definition: itype.h:909
std::set< weapon_category_id > weapon_category
Definition: itype.h:876
int min_int
Definition: itype.h:910
int min_per
Definition: itype.h:911
translation description
Definition: itype.h:879
std::map< skill_id, int > min_skills
Definition: itype.h:907
std::vector< std::pair< itype_id, mod_id > > src
Definition: itype.h:810

References _, active, age(), arrow, BASE_AMOUNT, BASE_CATEGORY, BASE_CONTENTS, BASE_DEBUG, BASE_ID, BASE_MATERIAL, BASE_MOD_SRC, BASE_REQUIREMENTS, BASE_VOLUME, BASE_WEIGHT, burnt, c_light_blue, charges, colorize(), convert_volume(), convert_weight(), count_by_charges(), craft_data_, damage_, debug, DESCRIPTION, itype::description, display_mod_source, display_object_ids, enumerate_as_string(), flag_STR_DRAW(), g, get_avatar(), get_category(), get_food(), itype::get_id(), get_min_str(), get_owner_name(), get_shelf_life(), snippet_library::get_snippet_by_id(), ranged::get_str_draw_penalty(), get_var(), goes_bad(), has_flag(), has_var(), info(), insert_separation_line(), is_craft(), iteminfo::is_decimal, is_food(), is_medication(), string_id< T >::is_null(), iteminfo::is_three_decimal, item_counter, item_tags, item_vars, last_rot_check, iteminfo::lower_is_better, made_of_types(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, om_direction::name(), iteminfo::no_flags, iteminfo::no_newline, none, owner, rot, round_up(), skill_id, snip_id, SNIPPET, sorted_lex(), sign::space, itype::src, string_format(), iteminfo_query::test(), translation::translated(), type, typeId(), volume(), volume_units_abbr(), WEAPON_CATEGORY, itype::weapon_category, weight(), and weight_units().

Referenced by info().

◆ battery_info()

void item::battery_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3084 of file item.cpp.

3086{
3087 if( !is_battery() ) {
3088 return;
3089 }
3090
3091 std::string info_string;
3092 if( type->battery->max_capacity < 1_kJ ) {
3093 info_string = string_format( _( "<bold>Capacity</bold>: %dJ" ),
3094 to_joule( type->battery->max_capacity ) );
3095 } else if( type->battery->max_capacity >= 1_kJ ) {
3096 info_string = string_format( _( "<bold>Capacity</bold>: %dkJ" ),
3097 to_kilojoule( type->battery->max_capacity ) );
3098 }
3100 info.emplace_back( "BATTERY", info_string );
3101}
bool is_battery() const
Definition: item.cpp:6572
std::string info_string() const
As info, but as a string rather than a vector of properties.
Definition: item.cpp:4088
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
cata::value_ptr< islot_battery > battery
Definition: itype.h:833

References _, itype::battery, info(), info_string(), insert_separation_line(), is_battery(), string_format(), units::to_joule(), units::to_kilojoule(), and type.

Referenced by info().

◆ bionic_info()

void item::bionic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3297 of file item.cpp.

3299{
3300 if( !is_bionic() ) {
3301 return;
3302 }
3303
3304 // TODO: Unhide when enforcing limits
3305 if( get_option < bool >( "CBM_SLOTS_ENABLED" )
3307 info.push_back( iteminfo( "DESCRIPTION", list_occupied_bps( type->bionic->id,
3308 _( "This bionic is installed in the following body "
3309 "part(s):" ) ) ) );
3310 }
3312
3313 const bionic_id bid = type->bionic->id;
3314 const std::vector<itype_id> &fuels = bid->fuel_opts;
3315 if( !fuels.empty() ) {
3316 const int &fuel_numb = fuels.size();
3317
3318 info.push_back( iteminfo( "DESCRIPTION",
3319 vgettext( "* This bionic can produce power from the following fuel: ",
3320 "* This bionic can produce power from the following fuels: ",
3321 fuel_numb ) + enumerate_as_string( fuels.begin(),
3322 fuels.end(), []( const itype_id & id ) -> std::string { return "<info>" + id->nname( 1 ) + "</info>"; } ) ) );
3323 }
3324
3326
3327 if( bid->capacity > 0_J ) {
3328 info.push_back( iteminfo( "CBM", _( "<bold>Power Capacity</bold>:" ), _( " <num> J" ),
3330 units::to_joule( bid->capacity ) ) );
3331 }
3332
3334
3335 if( !bid->encumbrance.empty() ) {
3336 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Encumbrance</bold>: " ),
3338 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->encumbrance ) ) {
3339 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3340 " <num> ", iteminfo::no_newline, element.second ) );
3341 }
3342 }
3343
3344 if( !bid->env_protec.empty() ) {
3345 info.push_back( iteminfo( "DESCRIPTION",
3346 bid->activated ? _( "<bold>Environmental Protection (activated)</bold>: " ) :
3347 _( "<bold>Environmental Protection</bold>: " ),
3349 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->env_protec ) ) {
3350 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3351 " <num> ", iteminfo::no_newline, element.second ) );
3352 }
3353 }
3354
3355 if( !bid->bash_protec.empty() ) {
3356 info.push_back( iteminfo( "DESCRIPTION",
3357 _( "<bold>Bash Protection</bold>: " ),
3359 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->bash_protec ) ) {
3360 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3361 " <num> ", iteminfo::no_newline, element.second ) );
3362 }
3363 }
3364
3365 if( !bid->cut_protec.empty() ) {
3366 info.push_back( iteminfo( "DESCRIPTION",
3367 _( "<bold>Cut Protection</bold>: " ),
3369 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->cut_protec ) ) {
3370 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3371 " <num> ", iteminfo::no_newline, element.second ) );
3372 }
3373 }
3374
3375 if( !bid->bullet_protec.empty() ) {
3376 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Ballistic Protection</bold>: " ),
3378 for( const auto &element : bid->bullet_protec ) {
3379 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3380 " <num> ", iteminfo::no_newline, element.second ) );
3381 }
3382 }
3383
3384 if( !bid->stat_bonus.empty() ) {
3385 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Stat Bonus</bold>: " ),
3387 for( const auto &element : bid->stat_bonus ) {
3388 info.push_back( iteminfo( "CBM", get_stat_name( element.first ), " <num> ",
3389 iteminfo::no_newline, element.second ) );
3390 }
3391 }
3392
3393 const units::mass weight_bonus = bid->weight_capacity_bonus;
3394 const float weight_modif = bid->weight_capacity_modifier;
3395 if( weight_modif != 1 ) {
3396 std::string modifier;
3397 if( weight_modif < 1 ) {
3398 modifier = "<num><bad>x</bad>";
3399 } else {
3400 modifier = "<num><color_light_green>x</color>";
3401 }
3402 info.push_back( iteminfo( "CBM",
3403 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
3405 weight_modif ) );
3406 }
3407 if( weight_bonus != 0_gram ) {
3408 std::string bonus;
3409 if( weight_bonus < 0_gram ) {
3410 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
3411 } else {
3412 bonus = string_format( "<num> <color_light_green>%s</color>", weight_units() );
3413 }
3414 info.push_back( iteminfo( "CBM", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
3416 convert_weight( weight_bonus ) ) );
3417 }
3418}
std::string list_occupied_bps(const bionic_id &bio_id, const std::string &intro, const bool each_bp_on_new_line)
Definition: bionics.cpp:2525
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:343
std::string get_stat_name(character_stat Stat)
Get translated name of a stat.
Definition: character.cpp:7761
bool is_bionic() const
Definition: item.cpp:6562
std::map< bodypart_str_id, int > cut_protec
Amount of cut protection offered by this bionic.
Definition: bionics.h:88
units::energy capacity
Power bank size.
Definition: bionics.h:49
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:53
std::map< character_stat, int > stat_bonus
Map of stats and their corresponding bonuses passively granted by a bionic.
Definition: bionics.h:63
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:67
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: bionics.h:59
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: bionics.h:61
std::map< bodypart_str_id, int > encumbrance
Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
Definition: bionics.h:99
std::map< bodypart_str_id, int > bullet_protec
Amount of bullet protection offered by this bionic.
Definition: bionics.h:90
std::map< bodypart_str_id, int > bash_protec
Amount of bash protection offered by this bionic.
Definition: bionics.h:86
std::map< bodypart_str_id, int > env_protec
Amount of environemental protection offered by this bionic.
Definition: bionics.h:84
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:834
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, bionic_data::activated, bionic_data::bash_protec, itype::bionic, body_part_name_as_heading(), bionic_data::bullet_protec, bionic_data::capacity, convert_weight(), bionic_data::cut_protec, DESCRIPTION_CBM_SLOTS, bionic_data::encumbrance, enumerate_as_string(), bionic_data::env_protec, bionic_data::fuel_opts, get_stat_name(), info(), insert_separation_line(), is_bionic(), iteminfo::is_decimal, list_occupied_bps(), iteminfo::no_newline, sorted_lex(), bionic_data::stat_bonus, string_format(), iteminfo_query::test(), units::to_joule(), type, vgettext(), bionic_data::weight_capacity_bonus, bionic_data::weight_capacity_modifier, and weight_units().

Referenced by final_info().

◆ birthday()

◆ bonus_from_enchantments()

double item::bonus_from_enchantments ( const Character owner,
double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only.

Definition at line 6997 of file item.cpp.

6999{
7000 double add = 0.0;
7001 double mul = 0.0;
7002 for( const enchantment &ench : get_enchantments() ) {
7003 if( ench.is_active( owner, *this ) ) {
7004 add += ench.get_value_add( value );
7005 mul += ench.get_value_multiply( value );
7006 }
7007 }
7008 // TODO: this part duplicates enchantment::calc_bonus()
7009 double ret = add + base * mul;
7010 if( round ) {
7011 ret = trunc( ret );
7012 }
7013 return ret;
7014}
const std::vector< enchantment > & get_enchantments() const
Definition: item.cpp:6988
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4206

References om_direction::add(), get_enchantments(), owner, and cata::hash64_detail::ret.

Referenced by item_armor_enchantment_adjust().

◆ bonus_from_enchantments_wielded()

double item::bonus_from_enchantments_wielded ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied.

Definition at line 7016 of file item.cpp.

7018{
7019 double add = 0.0;
7020 double mul = 0.0;
7021 for( const enchantment &ench : get_enchantments() ) {
7022 if( ench.is_active_when_wielded() ) {
7023 add += ench.get_value_add( value );
7024 mul += ench.get_value_multiply( value );
7025 }
7026 }
7027 // TODO: this part duplicates enchantment::calc_bonus()
7028 double ret = add + base * mul;
7029 if( round ) {
7030 ret = trunc( ret );
7031 }
7032 return ret;
7033}

References om_direction::add(), get_enchantments(), and cata::hash64_detail::ret.

Referenced by attack_cost(), and damage_melee().

◆ book_info()

void item::book_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2919 of file item.cpp.

2921{
2922 if( !is_book() ) {
2923 return;
2924 }
2925
2926 Character &character = get_player_character();
2927
2929 const islot_book &book = *type->book;
2930 // Some things about a book you CAN tell by it's cover.
2931 if( !book.skill && !type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2932 info.push_back( iteminfo( "BOOK", _( "Just for fun." ) ) );
2933 }
2934 if( type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2935 info.push_back( iteminfo( "BOOK",
2936 _( "Some sort of <info>martial arts training "
2937 "manual</info>." ) ) );
2938 const matype_id style_to_learn = martial_art_learned_from( *type );
2939 info.push_back( iteminfo( "BOOK",
2940 string_format( _( "You can learn <info>%s</info> style "
2941 "from it." ), style_to_learn->name ) ) );
2942 info.push_back( iteminfo( "BOOK",
2943 string_format( _( "This fighting style is <info>%s</info> "
2944 "to learn." ),
2945 martialart_difficulty( style_to_learn ) ) ) );
2946 info.push_back( iteminfo( "BOOK",
2947 string_format( _( "It'd be easier to master if you'd have "
2948 "skill expertise in <info>%s</info>." ),
2949 style_to_learn->primary_skill->name() ) ) );
2950 }
2951 if( book.req == 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER ) ) {
2952 info.push_back( iteminfo( "BOOK", _( "It can be <info>understood by "
2953 "beginners</info>." ) ) );
2954 }
2955 avatar &you = get_avatar();
2956 if( !you.has_identified( typeId() ) && parts->test( iteminfo_parts::BOOK_UNREAD ) ) {
2957 info.push_back( iteminfo( "BOOK",
2958 _( "You have <info>never read</info> this book." ) ) );
2959 }
2960 if( book.skill ) {
2961 const SkillLevel &skill = you.get_skill_level_object( book.skill );
2962 if( skill.can_train() && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MAX ) ) {
2963 const std::string skill_name = book.skill->name();
2964 std::string fmt = string_format( _( "Can bring your <info>%s skill to</info> "
2965 "<num>." ), skill_name );
2966 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, book.level ) );
2967 fmt = string_format( _( "Your current <stat>%s skill</stat> is <num>." ),
2968 skill_name );
2969 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, skill.level() ) );
2970 }
2971
2972 if( book.req != 0 && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MIN ) ) {
2973 const std::string fmt = string_format(
2974 _( "<info>Requires %s level</info> <num> to "
2975 "understand." ), book.skill.obj().name() );
2976 info.push_back( iteminfo( "BOOK", "", fmt,
2978 }
2979 }
2980
2981 if( book.intel != 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_INT ) ) {
2982 info.push_back( iteminfo( "BOOK", "",
2983 _( "Requires <info>intelligence of</info> <num> to easily "
2984 "read." ), iteminfo::lower_is_better, book.intel ) );
2985 }
2986 if( character_funcs::get_book_fun_for( character, *this ) != 0 &&
2988 info.push_back( iteminfo( "BOOK", "",
2989 _( "Reading this book affects your morale by <num>" ),
2991 }
2993 std::string fmt = vgettext(
2994 "A chapter of this book takes <num> <info>minute to "
2995 "read</info>.",
2996 "A chapter of this book takes <num> <info>minutes to "
2997 "read</info>.", book.time );
2998 if( type->use_methods.count( "MA_MANUAL" ) ) {
2999 fmt = vgettext(
3000 "<info>A training session</info> with this book takes "
3001 "<num> <info>minute</info>.",
3002 "<info>A training session</info> with this book takes "
3003 "<num> <info>minutes</info>.", book.time );
3004 }
3005 info.push_back( iteminfo( "BOOK", "", fmt,
3007 }
3008
3009 if( book.chapters > 0 && parts->test( iteminfo_parts::BOOK_NUMUNREADCHAPTERS ) ) {
3010 const int unread = get_remaining_chapters( you );
3011 std::string fmt = vgettext( "This book has <num> <info>unread chapter</info>.",
3012 "This book has <num> <info>unread chapters</info>.",
3013 unread );
3014 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, unread ) );
3015 }
3016
3017 std::vector<std::string> recipe_list;
3018 for( const islot_book::recipe_with_description_t &elem : book.recipes ) {
3019 const bool knows_it = you.knows_recipe( elem.recipe );
3020 const bool can_learn = you.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level;
3021 // If the player knows it, they recognize it even if it's not clearly stated.
3022 if( elem.is_hidden() && !knows_it ) {
3023 continue;
3024 }
3025 if( knows_it ) {
3026 // In case the recipe is known, but has a different name in the book, use the
3027 // real name to avoid confusing the player.
3028 const std::string name = elem.recipe->result_name();
3029 recipe_list.push_back( "<bold>" + name + "</bold>" );
3030 } else if( !can_learn ) {
3031 recipe_list.push_back( "<color_brown>" + elem.name + "</color>" );
3032 } else {
3033 recipe_list.push_back( "<dark>" + elem.name + "</dark>" );
3034 }
3035 }
3036
3037 if( !recipe_list.empty() && parts->test( iteminfo_parts::DESCRIPTION_BOOK_RECIPES ) ) {
3038 std::string recipe_line =
3039 string_format( vgettext( "This book contains %1$d crafting recipe: %2$s",
3040 "This book contains %1$d crafting recipes: %2$s",
3041 recipe_list.size() ),
3042 recipe_list.size(), enumerate_as_string( recipe_list ) );
3043
3045 info.push_back( iteminfo( "DESCRIPTION", recipe_line ) );
3046 }
3047
3048 if( recipe_list.size() != book.recipes.size() &&
3050 info.push_back( iteminfo( "DESCRIPTION",
3051 _( "It might help you figuring out some <good>more "
3052 "recipes</good>." ) ) );
3053 }
3054}
Character & get_player_character()
Definition: character.cpp:402
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3345
bool knows_recipe(const recipe *rec) const
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3350
int level() const
Definition: skill.h:125
bool can_train() const
Definition: skill.cpp:311
std::string name() const
Definition: skill.h:68
bool has_identified(const itype_id &item_id) const
Note that we've read a book at least once.
Definition: avatar.cpp:954
bool is_book() const
Definition: item.cpp:6719
int get_remaining_chapters(const Character &ch) const
Get the number of unread chapters.
Definition: item.cpp:7107
translation name
Definition: martialarts.h:270
skill_id primary_skill
Definition: martialarts.h:274
std::string result_name() const
Definition: recipe.cpp:615
skill_id skill_used
Definition: recipe.h:109
@ BOOK_REQUIREMENTS_BEGINNER
@ DESCRIPTION_BOOK_ADDITIONAL_RECIPES
std::string martialart_difficulty(const matype_id &mstyle)
matype_id martial_art_learned_from(const itype &type)
Definition: martialarts.cpp:90
int get_book_fun_for(const Character &ch, const item &book)
Returns enjoyability value of a book for given character.
What recipes can be learned from this book.
Definition: itype.h:360
std::string name
The name for the recipe as it appears in the book.
Definition: itype.h:372
int skill_level
The skill level required to learn the recipe.
Definition: itype.h:368
const class recipe * recipe
The recipe that can be learned (never null).
Definition: itype.h:364
int level
The skill level the book provides.
Definition: itype.h:335
int intel
Intelligence required to read it.
Definition: itype.h:347
skill_id skill
Which skill it upgrades, if any.
Definition: itype.h:327
int req
The skill level required to understand it.
Definition: itype.h:339
recipe_list_t recipes
Definition: itype.h:385
int time
How long in minutes it takes to read.
Definition: itype.h:352
int chapters
Fun books have chapters; after all are read, the book is less fun.
Definition: itype.h:356
@ show_plus
Use a + sign for positive values.
Definition: item.h:149
cata::value_ptr< islot_book > book
Definition: itype.h:825
std::map< std::string, use_function > use_methods
Actions an instance can perform (if any) indexed by action type.
Definition: itype.h:896

References _, itype::book, BOOK_MORALECHANGE, BOOK_NUMUNREADCHAPTERS, BOOK_REQUIREMENTS_BEGINNER, BOOK_REQUIREMENTS_INT, BOOK_SKILLRANGE_MAX, BOOK_SKILLRANGE_MIN, BOOK_SUMMARY, BOOK_TIMEPERCHAPTER, BOOK_UNREAD, SkillLevel::can_train(), itype::can_use(), islot_book::chapters, DESCRIPTION_BOOK_ADDITIONAL_RECIPES, DESCRIPTION_BOOK_RECIPES, enumerate_as_string(), get_avatar(), character_funcs::get_book_fun_for(), get_player_character(), get_remaining_chapters(), Character::get_skill_level(), Character::get_skill_level_object(), avatar::has_identified(), info(), insert_separation_line(), islot_book::intel, is_book(), islot_book::recipe_with_description_t::is_hidden(), Character::knows_recipe(), islot_book::level, SkillLevel::level(), iteminfo::lower_is_better, martial_art_learned_from(), martialart_difficulty(), islot_book::recipe_with_description_t::name, martialart::name, Skill::name(), om_direction::name(), iteminfo::no_flags, string_id< T >::obj(), martialart::primary_skill, islot_book::recipe_with_description_t::recipe, islot_book::recipes, islot_book::req, recipe::result_name(), iteminfo::show_plus, islot_book::skill, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, string_format(), iteminfo_query::test(), islot_book::time, type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ brewing_results()

const std::vector< itype_id > & item::brewing_results ( ) const

The results of fermenting this item.

Definition at line 5961 of file item.cpp.

5962{
5963 static const std::vector<itype_id> nulresult{};
5964 return is_brewable() ? type->brewable->results : nulresult;
5965}
bool is_brewable() const
Definition: item.cpp:6613
cata::value_ptr< islot_brewable > brewable
Definition: itype.h:822

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ brewing_time()

time_duration item::brewing_time ( ) const

Time for this item to be fully fermented.

Definition at line 5956 of file item.cpp.

5957{
5958 return is_brewable() ? type->brewable->time : 0_turns;
5959}

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ bullet_resist()

int item::bullet_resist ( bool  to_self = false) const

Definition at line 6108 of file item.cpp.

6109{
6110 if( is_null() ) {
6111 return 0;
6112 }
6113
6114 const int base_thickness = get_thickness();
6115 float resist = 0;
6117 int eff_thickness = 1;
6118
6119 // base resistance
6120 // Don't give reinforced items +armor, just more resistance to ripping
6121 const int dmg = damage_level( 4 );
6122 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6123 eff_thickness = std::max( 1, base_thickness - eff_damage );
6124
6125 const std::vector<const material_type *> mat_types = made_of_types();
6126 if( !mat_types.empty() ) {
6127 for( const material_type *mat : mat_types ) {
6128 resist += mat->bullet_resist();
6129 }
6130 // Average based on number of materials.
6131 resist /= mat_types.size();
6132 }
6133
6134 return std::lround( ( resist * eff_thickness ) + mod );
6135}
@ clothing_mod_type_bullet
Definition: clothing_mod.h:21

References clothing_mod_type_bullet, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ burn()

bool item::burn ( fire_data frd)

Burns the item.

Returns true if the item was destroyed.

Definition at line 8285 of file item.cpp.

8286{
8287 float burn_added = simulate_burn( frd );
8288
8289 if( burn_added <= 0 ) {
8290 return false;
8291 }
8292
8293 if( count_by_charges() ) {
8294 if( type->volume == 0_ml ) {
8295 charges = 0;
8296 } else {
8298 ( 3.0 * type->volume ) );
8299 }
8300
8301 return charges <= 0;
8302 }
8303
8304 if( is_corpse() ) {
8305 const mtype *mt = get_mtype();
8306 if( active && mt != nullptr && burnt + burn_added > mt->hp &&
8307 !mt->burn_into.is_null() && mt->burn_into.is_valid() ) {
8308 corpse = &get_mtype()->burn_into.obj();
8309 // Delay rezing
8310 set_age( 0_turns );
8311 burnt = 0;
8312 return false;
8313 }
8314 }
8315
8316 burnt += roll_remainder( burn_added );
8317
8318 const int vol = base_volume() / units::legacy_volume_factor;
8319 return burnt >= vol * 3;
8320}
units::volume base_volume() const
Simplified, faster volume check for when processing time is important and exact volume is not.
Definition: item.cpp:5103
float simulate_burn(fire_data &frd) const
Calculate all burning calculations, but don't actually apply them to item.
Definition: item.cpp:8232
const mtype * get_mtype() const
Definition: item.cpp:6635
void set_age(const time_duration &age)
Definition: item.cpp:10017
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:70
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
int roll_remainder(double value)
Definition: rng.cpp:96
Definition: mtype.h:209
mtype_id burn_into
Definition: mtype.h:332
int hp
Definition: mtype.h:271

References active, base_volume(), mtype::burn_into, burnt, charges, corpse, count_by_charges(), get_mtype(), mtype::hp, is_corpse(), string_id< T >::is_null(), string_id< T >::is_valid(), units::legacy_volume_factor, string_id< T >::obj(), roll_remainder(), set_age(), simulate_burn(), itype::stack_size, type, and itype::volume.

Referenced by Character::absorb_hit().

◆ calc_rot()

auto item::calc_rot ( time_point  time,
const units::temperature  temp 
) const -> time_duration

Returns rot of the item since last rot calculation.

This function should not be called directly. since it does not have all the needed checks or temperature calculations. If you need to calc rot of item call process_rot instead.

Parameters
timeTime point to which rot is calculated
tempTemperature at which the rot is calculated

Definition at line 5657 of file item.cpp.

5658{
5659 // Avoid needlessly calculating already rotten things. Corpses should
5660 // always rot away and food rots away at twice the shelf life. If the food
5661 // is in a sealed container they won't rot away, this avoids needlessly
5662 // calculating their rot in that case.
5663 if( !is_corpse() && get_relative_rot() > 2.0 ) {
5664 return 0_seconds;
5665 }
5666
5667 // rot modifier
5668 float factor = 1.0;
5669 if( is_corpse() && has_flag( flag_FIELD_DRESS ) ) {
5670 factor = 0.75;
5671 }
5672
5673 time_duration added_rot = 0_seconds;
5674 // simulation of different age of food at the start of the game and good/bad storage
5675 // conditions by applying starting variation bonus/penalty of +/- 20% of base shelf-life
5676 // positive = food was produced some time before calendar::start and/or bad storage
5677 // negative = food was stored in good conditions before calendar::start
5679 time_duration spoil_variation = get_shelf_life() * 0.2f;
5680 added_rot += rng( -spoil_variation, spoil_variation );
5681 }
5682 time_duration time_delta = time - last_rot_check;
5683 added_rot += factor * time_delta / 1_hours * get_hourly_rotpoints_at_temp( temp ) * 1_turns;
5684 return added_rot;
5685}
A duration defined as a number of specific time units.
Definition: calendar.h:180
static const std::string flag_FIELD_DRESS("FIELD_DRESS")
auto get_hourly_rotpoints_at_temp(const units::temperature temp) -> int
Get the hourly rot for a given temperature from the precomputed table.
Definition: item.cpp:5642
@ time
Recharges slowly with time.

References flag_FIELD_DRESS(), get_hourly_rotpoints_at_temp(), rng(), calendar::start_of_cataclysm, and time.

Referenced by process_rot().

◆ can_contain() [1/2]

bool item::can_contain ( const item it) const

Can this item have given item/itype as content?

For example, airtight for gas, acidproof for acid etc.

Definition at line 7040 of file item.cpp.

7041{
7042 // TODO: Volume check
7043 return can_contain( *it.type );
7044}
bool can_contain(const item &it) const
Can this item have given item/itype as content?
Definition: item.cpp:7040

References can_contain(), and type.

Referenced by can_contain().

◆ can_contain() [2/2]

bool item::can_contain ( const itype tp) const

Definition at line 7046 of file item.cpp.

7047{
7048 if( !type->container ) {
7049 // TODO: Tools etc.
7050 return false;
7051 }
7052
7053 if( tp.phase == LIQUID && !type->container->watertight ) {
7054 return false;
7055 }
7056
7057 // TODO: Acid in waterskins
7058 return true;
7059}
@ LIQUID
Definition: enums.h:175
phase_id phase
Definition: itype.h:913

References itype::container, LIQUID, itype::phase, and type.

◆ can_holster()

bool item::can_holster ( const item obj,
bool  ignore = false 
) const

Checks if item is a holster and currently capable of storing obj.

Parameters
objobject that we want to holster
ignoreonly check item is compatible and ignore any existing contents

Definition at line 8878 of file item.cpp.

8879{
8880 if( !type->can_use( "holster" ) ) {
8881 return false; // item is not a holster
8882 }
8883
8884 const holster_actor *ptr = dynamic_cast<const holster_actor *>
8885 ( type->get_use( "holster" )->get_actor_ptr() );
8886 if( !ptr->can_holster( obj ) ) {
8887 return false; // item is not a suitable holster for obj
8888 }
8889
8890 if( !ignore && static_cast<int>( contents.num_item_stacks() ) >= ptr->multi ) {
8891 return false; // item is already full
8892 }
8893
8894 return true;
8895}
Holster a weapon.
Definition: iuse_actor.h:842
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.

References itype::can_use(), contents, use_function::get_actor_ptr(), itype::get_use(), item_contents::num_item_stacks(), ptr(), and type.

◆ can_reload_with() [1/2]

bool item::can_reload_with ( const ammotype ammo) const

Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo.

Definition at line 6871 of file item.cpp.

6872{
6873 return is_reloadable_helper( ammo->default_ammotype(), false );
6874}
bool is_reloadable_helper(const itype_id &ammo, bool now) const
Helper for checking reloadability.
Definition: item.cpp:6886

References ammunition_type::default_ammotype(), and is_reloadable_helper().

Referenced by favorite_ammo_or_select(), avatar_funcs::gunmod_add(), and aim_activity_actor::load_RAS_weapon().

◆ can_reload_with() [2/2]

bool item::can_reload_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo.

Definition at line 6876 of file item.cpp.

6877{
6878 return is_reloadable_helper( ammo, false );
6879}

References is_reloadable_helper().

◆ can_revive()

bool item::can_revive ( ) const

Whether this is a corpse that can be revived.

Definition at line 5967 of file item.cpp.

5968{
5969 return is_corpse() && corpse->has_flag( MF_REVIVES ) && damage() < max_damage() &&
5973}
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6226
static const std::string flag_QUARTERED("QUARTERED")
static const std::string flag_SKINNED("SKINNED")
static const std::string flag_FIELD_DRESS_FAILED("FIELD_DRESS_FAILED")
static const std::string flag_PULPED("PULPED")
@ MF_REVIVES
Definition: mtype.h:126
bool has_flag(m_flag flag) const
Definition: mtype.cpp:75

References corpse, damage(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_PULPED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), mtype::has_flag(), is_corpse(), max_damage(), and MF_REVIVES.

Referenced by active_item_cache::add(), color_in_inventory(), has_rotten_away(), ready_to_revive(), active_item_cache::remove(), basecamp::start_relay_hide_site(), and basecamp::start_setup_hide_site().

◆ can_unload_liquid()

bool item::can_unload_liquid ( ) const

Returns true if not empty if it's liquid, it's not currently frozen in resealable container.

Definition at line 6860 of file item.cpp.

6861{
6862 if( is_container_empty() ) {
6863 return true;
6864 }
6865
6866 const item &cts = contents.front();
6867 bool cts_is_frozen_liquid = cts.made_of( LIQUID ) && cts.made_of( SOLID );
6868 return is_bucket() || !cts_is_frozen_liquid;
6869}
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6423
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6847
bool is_bucket() const
Definition: item.cpp:6744
@ SOLID
Definition: enums.h:175

References contents, item_contents::front(), is_bucket(), is_container_empty(), LIQUID, made_of(), and SOLID.

Referenced by item_funcs::can_be_unloaded(), iexamine::keg(), and avatar_funcs::unload_item().

◆ casings_count()

int item::casings_count ( ) const

How many spent casings are contained within this item?

Definition at line 8091 of file item.cpp.

8092{
8093 int res = 0;
8094
8095 const_cast<item *>( this )->casings_handle( [&res]( item & ) {
8096 ++res;
8097 return false;
8098 } );
8099
8100 return res;
8101}
void casings_handle(const std::function< bool(item &)> &func)
Apply predicate to each contained spent casing removing it if predicate returns true.
Definition: item.cpp:8103

References casings_handle().

Referenced by item_funcs::can_be_unloaded(), and avatar_funcs::unload_item().

◆ casings_handle()

void item::casings_handle ( const std::function< bool(item &)> &  func)

Apply predicate to each contained spent casing removing it if predicate returns true.

Definition at line 8103 of file item.cpp.

8104{
8105 if( !is_gun() ) {
8106 return;
8107 }
8108
8109 contents.casings_handle( func );
8110}
void casings_handle(const std::function< bool(item &)> &func)

References item_contents::casings_handle(), contents, and is_gun().

Referenced by casings_count(), avatar_funcs::gunmod_remove(), reload(), and avatar_funcs::unload_item().

◆ charges_per_volume()

int item::charges_per_volume ( const units::volume vol) const

Number of (charges of) this item that fit into the given volume.

May return 0 if not even one charge fits into the volume. Only depends on the type of this item not on its current charge count.

For items not counted by charges, this returns vol / this->volume().

Definition at line 869 of file item.cpp.

870{
871 if( count_by_charges() ) {
872 if( type->volume == 0_ml ) {
873 debugmsg( "Item '%s' with zero volume", tname() );
874 return INFINITE_CHARGES;
875 }
876 // Type cast to prevent integer overflow with large volume containers like the cargo
877 // dimension
878 return vol * static_cast<int64_t>( type->stack_size ) / type->volume;
879 } else {
880 units::volume my_volume = volume();
881 if( my_volume == 0_ml ) {
882 debugmsg( "Item '%s' with zero volume", tname() );
883 return INFINITE_CHARGES;
884 }
885 return vol / my_volume;
886 }
887}
static const int INFINITE_CHARGES
Definition: item.h:2168

References count_by_charges(), debugmsg, INFINITE_CHARGES, itype::stack_size, tname(), type, volume(), and itype::volume.

Referenced by item_stack::amount_can_fit(), Character::can_feed_furnace_with(), vehicle_part::consume_energy(), display_name(), Character::feed_furnace_with(), activity_handlers::fill_liquid_do_turn(), Character::get_acquirable_energy(), get_remaining_capacity_for_liquid(), in_container(), Item_factory::migrate_item(), Item_modifier::modify(), vehicle::print_fuel_indicator(), advanced_inventory::query_charges(), and try_fuel_fire().

◆ chip_resistance()

int item::chip_resistance ( bool  worst = false) const

Returns resistance to being damaged by attack against the item itself.

Calculated from item's materials.

Parameters
worstIf this is true, the worst resistance is used. Otherwise the best one.

Definition at line 6202 of file item.cpp.

6203{
6204 int res = worst ? INT_MAX : INT_MIN;
6205 for( const material_type *mat : made_of_types() ) {
6206 const int val = mat->chip_resist();
6207 res = worst ? std::min( res, val ) : std::max( res, val );
6208 }
6209
6210 if( res == INT_MAX || res == INT_MIN ) {
6211 return 2;
6212 }
6213
6214 if( res <= 0 ) {
6215 return 0;
6216 }
6217
6218 return res;
6219}

References made_of_types().

Referenced by Character::handle_melee_wear().

◆ clear_vars()

void item::clear_vars ( )

Removes all item variables.

Definition at line 1090 of file item.cpp.

1091{
1092 item_vars.clear();
1093}

References item_vars.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ color()

nc_color item::color ( ) const

Returns the default color of the item (e.g.

itype::color).

Definition at line 4937 of file item.cpp.

4938{
4939 if( is_null() ) {
4940 return c_black;
4941 }
4942 if( is_corpse() ) {
4943 return corpse->color;
4944 }
4945 return type->color;
4946}
#define c_black
Definition: color.h:17
nc_color color
Definition: itype.h:977
nc_color color
Definition: mtype.h:262

References c_black, itype::color, mtype::color, corpse, is_corpse(), is_null(), and type.

Referenced by map::draw_maptile(), Character::pour_into(), and debug_menu::wishitem().

◆ color_in_inventory() [1/2]

nc_color item::color_in_inventory ( ) const

Returns the color of the item depending on usefulness for the player character, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Definition at line 4149 of file item.cpp.

4150{
4152}
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4149

References color_in_inventory(), and get_avatar().

Referenced by color_in_inventory(), colorized_item_name(), inventory_selector_preset::get_color(), read_inventory_preset::get_color(), avatar_funcs::gunmod_add(), game::list_items(), iuse::marloss_seed(), pickup::pick_up(), iuse::seed(), Character::takeoff(), and Character::will_eat().

◆ color_in_inventory() [2/2]

nc_color item::color_in_inventory ( const player p) const

Returns the color of the item depending on usefulness for the passed player, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Parameters
for_playerNPC or avatar which would read book.

Definition at line 4154 of file item.cpp.

4155{
4156 // Only item not otherwise colored gets colored as favorite
4158 if( type->can_use( "learn_spell" ) ) {
4159 const use_function *iuse = get_use( "learn_spell" );
4160 const learn_spell_actor *actor_ptr =
4161 static_cast<const learn_spell_actor *>( iuse->get_actor_ptr() );
4162 for( const std::string &spell_id_str : actor_ptr->spells ) {
4163 const spell_id sp_id( spell_id_str );
4164 if( p.magic->knows_spell( sp_id ) && !p.magic->get_spell( sp_id ).is_max_level() ) {
4165 ret = c_yellow;
4166 }
4167 if( !p.magic->knows_spell( sp_id ) && p.magic->can_learn_spell( p, sp_id ) ) {
4168 return c_light_blue;
4169 }
4170 }
4171 } else if( has_flag( flag_WET ) ) {
4172 ret = c_cyan;
4173 } else if( has_flag( flag_LITCIG ) ) {
4174 ret = c_red;
4175 } else if( is_armor() && p.has_trait( trait_WOOLALLERGY ) &&
4176 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
4177 ret = c_red;
4178 } else if( is_filthy() || has_own_flag( "DIRTY" ) ) {
4179 ret = c_brown;
4180 } else if( is_bionic() ) {
4181 if( !p.has_bionic( type->bionic->id ) ) {
4182 ret = p.bionic_installation_issues( type->bionic->id ).empty() ? c_green : c_red;
4183 } else if( !has_fault( fault_bionic_nonsterile ) ) {
4184 ret = c_dark_gray;
4185 }
4186 } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) {
4188 } else if( active && !is_food() && !is_food_container() && !is_corpse() ) {
4189 // Active items show up as yellow
4190 ret = c_yellow;
4191 } else if( is_corpse() && can_revive() ) {
4192 // Only reviving corpses are yellow
4193 ret = c_yellow;
4194 } else if( const item *food = get_food() ) {
4195 const bool preserves = type->container && type->container->preserves;
4196
4197 // Give color priority to allergy (allergy > inedible by freeze or other conditions)
4198 // TODO: refactor u.will_eat to let this section handle coloring priority without duplicating code.
4199 if( p.allergy_type( *food ) != morale_type( "morale_null" ) ) {
4200 return c_red;
4201 }
4202
4203 // Default: permafood, drugs
4204 // Brown: rotten (for non-saprophages) or non-rotten (for saprophages)
4205 // Dark gray: inedible
4206 // Red: morale penalty
4207 // Yellow: will rot soon
4208 // Cyan: will rot eventually
4209 const ret_val<edible_rating> rating = p.will_eat( *food );
4210 // TODO: More colors
4211 switch( rating.value() ) {
4214 if( preserves ) {
4215 // Nothing, canned food won't rot
4216 } else if( food->is_going_bad() ) {
4217 ret = c_yellow;
4218 } else if( food->goes_bad() ) {
4219 ret = c_cyan;
4220 }
4221 break;
4224 ret = c_dark_gray;
4225 break;
4229 ret = c_red;
4230 break;
4232 ret = c_brown;
4233 break;
4236 ret = c_pink;
4237 break;
4239 break;
4240 }
4241 } else if( is_gun() ) {
4242 // Guns are green if you are carrying ammo for them
4243 // ltred if you have ammo but no mags
4244 // Gun with integrated mag counts as both
4245 for( const ammotype &at : ammo_types() ) {
4246 // get_ammo finds uncontained ammo, find_ammo finds ammo in magazines
4247 bool has_ammo = !character_funcs::get_ammo_items( p, at ).empty() ||
4248 !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4249 bool has_mag = magazine_integral() ||
4250 !character_funcs::find_ammo_items_or_mags( p, *this, true, -1 ).empty();
4251 if( has_ammo && has_mag ) {
4252 ret = c_green;
4253 break;
4254 } else if( has_ammo || has_mag ) {
4255 ret = c_light_red;
4256 break;
4257 }
4258 }
4259 } else if( is_ammo() ) {
4260 // Likewise, ammo is green if you have guns that use it
4261 // ltred if you have the gun but no mags
4262 // Gun with integrated mag counts as both
4263 bool has_gun = p.has_item_with( [this]( const item & i ) {
4264 return i.is_gun() && i.ammo_types().count( ammo_type() );
4265 } );
4266 bool has_mag = p.has_item_with( [this]( const item & i ) {
4267 return ( i.is_gun() && i.magazine_integral() && i.ammo_types().count( ammo_type() ) ) ||
4268 ( i.is_magazine() && i.ammo_types().count( ammo_type() ) );
4269 } );
4270 if( has_gun && has_mag ) {
4271 ret = c_green;
4272 } else if( has_gun || has_mag ) {
4273 ret = c_light_red;
4274 }
4275 } else if( is_magazine() ) {
4276 // Magazines are green if you have guns and ammo for them
4277 // ltred if you have one but not the other
4278 bool has_gun = p.has_item_with( [this]( const item & it ) {
4279 return it.is_gun() && it.magazine_compatible().count( typeId() ) > 0;
4280 } );
4281 bool has_ammo = !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4282 if( has_gun && has_ammo ) {
4283 ret = c_green;
4284 } else if( has_gun || has_ammo ) {
4285 ret = c_light_red;
4286 }
4287 } else if( is_book() ) {
4288 const islot_book &tmp = *type->book;
4289 // Player doesn't actually interested if NPC has identified book yet.
4290 // So we check identification for human avatar.
4291 if( get_avatar().has_identified( typeId() ) ) {
4292 if( tmp.skill && // Book can improve skill: blue
4294 p.get_skill_level( tmp.skill ) >= tmp.req &&
4295 p.get_skill_level( tmp.skill ) < tmp.level ) {
4296 ret = c_light_blue;
4297 } else if( type->can_use( "MA_MANUAL" ) &&
4298 !p.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) {
4299 ret = c_light_blue;
4300 } else if( tmp.skill && // Book can't improve skill right now, but maybe later: pink
4302 p.get_skill_level( tmp.skill ) < tmp.level ) {
4303 ret = c_pink;
4304 } else if( !p.studied_all_recipes(
4305 *type ) ) { // Book can't improve skill anymore, but has more recipes: yellow
4306 ret = c_yellow;
4307 }
4308 } else if( tmp.skill || type->can_use( "MA_MANUAL" ) ) {
4309 // Book can teach you something and hasn't been identified yet
4310 ret = c_red;
4311 } else {
4312 // "just for fun" book that they haven't read yet
4313 ret = c_magenta;
4314 }
4315 }
4316 return ret;
4317}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1586
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1815
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2555
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
pimpl< known_magic > magic
Definition: character.h:1483
bool is_favorite
Definition: item.h:2249
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7698
bool has_fault(const fault_id &fault) const
Does this item have the specified fault.
Definition: item.cpp:5320
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:9988
bool is_food_container() const
Definition: item.cpp:6618
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7949
bool can_revive() const
Whether this is a corpse that can be revived.
Definition: item.cpp:5967
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5325
Learn a spell.
Definition: iuse_actor.h:799
std::vector< std::string > spells
Definition: iuse_actor.h:802
bool studied_all_recipes(const itype &book) const
Definition: player.cpp:265
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
T value() const
Definition: ret_val.h:74
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:105
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
#define c_yellow
Definition: color.h:32
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
#define c_red
Definition: color.h:21
static const std::string flag_WET("WET")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const std::string flag_LEAK_DAM("LEAK_DAM")
static const std::string flag_LITCIG("LITCIG")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")
std::vector< const item * > get_ammo_items(const Character &who, const ammotype &at)
Returns character's items that are ammo and have the matching ammo type.
std::vector< item_location > find_ammo_items_or_mags(const Character &who, const item &obj, bool empty, int radius)
Searches for ammo or magazines that can be used to reload given item.
Definition: iuse.h:25
string_id< material_type > material_id
Definition: type_id.h:95

References active, allergy, Character::allergy_type(), allergy_weak, ammo_type(), ammo_types(), itype::bionic, Character::bionic_installation_issues(), bloated, itype::book, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, can_revive(), SkillLevel::can_train(), itype::can_use(), cannibalism, itype::container, damage(), edible, fault_bionic_nonsterile, character_funcs::find_ammo_items_or_mags(), flag_LEAK_DAM(), flag_LITCIG(), flag_RADIOACTIVE(), flag_WET(), character_funcs::get_ammo_items(), get_avatar(), get_food(), Character::get_skill_level(), Character::get_skill_level_object(), get_use(), Character::has_bionic(), has_fault(), has_flag(), visitable< T >::has_item_with(), has_own_flag(), Character::has_trait(), inedible, inedible_mutation, is_ammo(), is_armor(), is_bionic(), is_book(), is_corpse(), is_favorite, is_filthy(), is_food(), is_food_container(), is_gun(), is_magazine(), islot_book::level, made_of(), magazine_compatible(), magazine_integral(), Character::magic, martial_art_learned_from(), Character::martial_arts_data, nausea, no_tool, islot_book::req, cata::hash64_detail::ret, rotten, islot_book::skill, learn_spell_actor::spells, player::studied_all_recipes(), too_full, trait_WOOLALLERGY, type, typeId(), ret_val< T >::value(), and Character::will_eat().

◆ combat_info()

void item::combat_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3420 of file item.cpp.

3422{
3423 const std::string space = " ";
3424
3425 int dmg_bash = damage_melee( DT_BASH );
3426 int dmg_cut = damage_melee( DT_CUT );
3427 int dmg_stab = damage_melee( DT_STAB );
3428 if( parts->test( iteminfo_parts::BASE_DAMAGE ) ) {
3430 std::string sep;
3431 if( dmg_bash || dmg_cut || dmg_stab ) {
3432 info.push_back( iteminfo( "BASE", _( "<bold>Melee damage</bold>: " ), "", iteminfo::no_newline ) );
3433 }
3434 if( dmg_bash ) {
3435 info.push_back( iteminfo( "BASE", _( "Bash: " ), "", iteminfo::no_newline, dmg_bash ) );
3436 sep = space;
3437 }
3438 if( dmg_cut ) {
3439 info.push_back( iteminfo( "BASE", sep + _( "Cut: " ), "", iteminfo::no_newline, dmg_cut ) );
3440 sep = space;
3441 }
3442 if( dmg_stab ) {
3443 info.push_back( iteminfo( "BASE", sep + _( "Pierce: " ), "", iteminfo::no_newline, dmg_stab ) );
3444 }
3445 }
3446
3447 if( dmg_bash || dmg_cut || dmg_stab ) {
3448 if( parts->test( iteminfo_parts::BASE_TOHIT ) ) {
3449 info.push_back( iteminfo( "BASE", space + _( "To-hit bonus: " ), "",
3451 }
3452
3453 if( parts->test( iteminfo_parts::BASE_MOVES ) ) {
3454 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "",
3456 info.emplace_back( "BASE", _( "Typical damage per second:" ), "" );
3457 const std::map<std::string, double> &dps_data = dps( true, false );
3458 std::string sep;
3459 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
3460 info.emplace_back( "BASE", sep + dps_entry.first + ": ", "",
3462 dps_entry.second );
3463 sep = space;
3464 }
3465 info.emplace_back( "BASE", "" );
3466 }
3467 }
3468
3470 std::set<matec_id> all_techniques = type->techniques;
3471 all_techniques.insert( techniques.begin(), techniques.end() );
3472
3473 if( !all_techniques.empty() ) {
3474 const std::vector<matec_id> all_tec_sorted = sorted_lex( all_techniques );
3476 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Techniques when wielded</bold>: " ) +
3477 enumerate_as_string( all_tec_sorted.begin(), all_tec_sorted.end(), []( const matec_id & tid ) {
3478 return string_format( "<stat>%s</stat>: <info>%s</info>", _( tid.obj().name ),
3479 _( tid.obj().description ) );
3480 } ) ) );
3481 }
3482 }
3483
3484 avatar &you = get_avatar();
3485 // display which martial arts styles character can use with this weapon
3487 const std::string valid_styles = you.martial_arts_data->enumerate_known_styles( typeId() );
3488 if( !valid_styles.empty() ) {
3490 info.push_back( iteminfo( "DESCRIPTION",
3491 _( "You know how to use this with these martial arts "
3492 "styles: " ) + valid_styles ) );
3493 }
3494 }
3495
3496 if( !is_gunmod() && has_flag( flag_REACH_ATTACK ) &&
3499 if( has_flag( flag_REACH3 ) ) {
3500 info.push_back( iteminfo( "DESCRIPTION",
3501 _( "* This item can be used to make <stat>long reach "
3502 "attacks</stat>." ) ) );
3503 } else {
3504 info.push_back( iteminfo( "DESCRIPTION",
3505 _( "* This item can be used to make <stat>reach "
3506 "attacks</stat>." ) ) );
3507 }
3508 }
3509
3510 if( ( dmg_bash || dmg_cut || dmg_stab || type->m_to_hit > 0 ) || debug_mode ) {
3511 damage_instance non_crit;
3512 you.roll_all_damage( false, non_crit, true, *this );
3513 damage_instance crit;
3514 you.roll_all_damage( true, crit, true, *this );
3515 int attack_cost = you.attack_cost( *this );
3518 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Average melee damage</bold>:" ) ) );
3519 }
3520 // Chance of critical hit
3522 info.push_back( iteminfo( "DESCRIPTION",
3523 string_format( _( "Critical hit chance <neutral>%d%% - %d%%</neutral>" ),
3524 static_cast<int>( you.crit_chance( 0, 100, *this ) *
3525 100 ),
3526 static_cast<int>( you.crit_chance( 100, 0, *this ) *
3527 100 ) ) ) );
3528 }
3529 // Bash damage
3531 // NOTE: Using "BASE" instead of "DESCRIPTION", so numerical formatting will work
3532 // (output.cpp:format_item_info does not interpolate <num> for DESCRIPTION info)
3533 info.push_back( iteminfo( "BASE", _( "Bashing: " ), "<num>", iteminfo::no_newline,
3534 non_crit.type_damage( DT_BASH ) ) );
3535 info.push_back( iteminfo( "BASE", space + _( "Critical bash: " ), "<num>", iteminfo::no_flags,
3536 crit.type_damage( DT_BASH ) ) );
3537 }
3538 // Cut damage
3539 if( ( non_crit.type_damage( DT_CUT ) > 0.0f || crit.type_damage( DT_CUT ) > 0.0f )
3541
3542 info.push_back( iteminfo( "BASE", _( "Cutting: " ), "<num>", iteminfo::no_newline,
3543 non_crit.type_damage( DT_CUT ) ) );
3544 info.push_back( iteminfo( "BASE", space + _( "Critical cut: " ), "<num>", iteminfo::no_flags,
3545 crit.type_damage( DT_CUT ) ) );
3546 }
3547 // Pierce/stab damage
3548 if( ( non_crit.type_damage( DT_STAB ) > 0.0f || crit.type_damage( DT_STAB ) > 0.0f )
3550
3551 info.push_back( iteminfo( "BASE", _( "Piercing: " ), "<num>", iteminfo::no_newline,
3552 non_crit.type_damage( DT_STAB ) ) );
3553 info.push_back( iteminfo( "BASE", space + _( "Critical pierce: " ), "<num>", iteminfo::no_flags,
3554 crit.type_damage( DT_STAB ) ) );
3555 }
3556 // Moves
3558 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "<num>",
3560 }
3562 }
3563}
bool debug_mode
Extended debugging mode, can be toggled during game.
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2279
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:796
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:412
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5208
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
static const std::string flag_REACH3("REACH3")
static const std::string flag_REACH_ATTACK("REACH_ATTACK")
@ DESCRIPTION_MELEEDMG_PIERCE
@ DESCRIPTION_GUNMOD_ADDREACHATTACK
@ DESCRIPTION_MELEEDMG_MOVES
@ DESCRIPTION_APPLICABLEMARTIALARTS
float type_damage(damage_type dt) const
Definition: damage.cpp:64
int m_to_hit
Definition: itype.h:969
std::set< matec_id > techniques
Definition: itype.h:904

References _, attack_cost(), Character::attack_cost(), BASE_DAMAGE, BASE_MOVES, BASE_TOHIT, Character::crit_chance(), damage_melee(), debug_mode, DESCRIPTION_APPLICABLEMARTIALARTS, DESCRIPTION_GUNMOD_ADDREACHATTACK, DESCRIPTION_MELEEDMG, DESCRIPTION_MELEEDMG_BASH, DESCRIPTION_MELEEDMG_CRIT, DESCRIPTION_MELEEDMG_CUT, DESCRIPTION_MELEEDMG_MOVES, DESCRIPTION_MELEEDMG_PIERCE, DESCRIPTION_TECHNIQUES, dps(), DT_BASH, DT_CUT, DT_STAB, enumerate_as_string(), flag_REACH3(), flag_REACH_ATTACK(), get_avatar(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, is_gunmod(), iteminfo::lower_is_better, itype::m_to_hit, Character::martial_arts_data, iteminfo::no_flags, iteminfo::no_newline, Character::roll_all_damage(), iteminfo::show_plus, sorted_lex(), sign::space, string_format(), techniques, itype::techniques, iteminfo_query::test(), type, damage_instance::type_damage(), and typeId().

Referenced by info().

◆ common_ammo_default()

itype_id item::common_ammo_default ( bool  conversion = true) const

Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists

Definition at line 7614 of file item.cpp.

7615{
7616 if( !ammo_types( conversion ).empty() ) {
7617 for( const ammotype &at : ammo_types( conversion ) ) {
7618 const item *mag = magazine_current();
7619 if( mag && mag->type->magazine->type.count( at ) ) {
7620 itype_id res = at->default_ammotype();
7621 if( !res.is_empty() ) {
7622 return res;
7623 }
7624 }
7625 }
7626 }
7627 return itype_id::NULL_ID();
7628}

References ammo_types(), string_id< T >::is_empty(), itype::magazine, magazine_current(), string_id< itype >::NULL_ID(), and type.

Referenced by gun_info().

◆ component_info()

void item::component_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3151 of file item.cpp.

3153{
3155 return;
3156 }
3157 if( is_craft() ) {
3158 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Using: %s" ),
3159 _( components_to_string() ) ) ) );
3160 // Ugly hack warning! Corpses have CBMs as their components
3161 } else if( !is_corpse() ) {
3162 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Made from: %s" ),
3163 _( components_to_string() ) ) ) );
3164 } else if( get_var( "bionics_scanned_by", -1 ) == get_avatar().getID().get_value() ) {
3165 // TODO: Extract into a more proper place (function in namespace)
3166 std::string bionics_string = enumerate_as_string( components.begin(), components.end(),
3167 []( const item & entry ) -> std::string {
3168 return entry.is_bionic() ? entry.display_name() : "";
3170 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Contains: %s" ),
3171 bionics_string ) ) );
3172 }
3173}
std::string components_to_string() const
List of all components in printable form, empty if this item has no components.
Definition: item.cpp:8897
@ DESCRIPTION_COMPONENTS_MADEFROM

References _, components, components_to_string(), DESCRIPTION_COMPONENTS_MADEFROM, enumerate_as_string(), get_avatar(), get_var(), info(), is_corpse(), is_craft(), none, string_format(), and iteminfo_query::test().

Referenced by info().

◆ components_to_string()

std::string item::components_to_string ( ) const

List of all components in printable form, empty if this item has no components.

Definition at line 8897 of file item.cpp.

8898{
8899 using t_count_map = std::map<std::string, int>;
8900 t_count_map counts;
8901 for( const item &elem : components ) {
8902 if( !elem.has_flag( flag_BYPRODUCT ) ) {
8903 const std::string name = elem.display_name();
8904 counts[name]++;
8905 }
8906 }
8907 return enumerate_as_string( counts.begin(), counts.end(),
8908 []( const std::pair<std::string, int> &entry ) -> std::string {
8909 if( entry.second != 1 )
8910 {
8911 return string_format( pgettext( "components count", "%d x %s" ), entry.second, entry.first );
8912 } else
8913 {
8914 return entry.first;
8915 }
8917}
static const std::string flag_BYPRODUCT("BYPRODUCT")

References components, enumerate_as_string(), flag_BYPRODUCT(), and om_direction::name().

Referenced by component_info().

◆ conductive()

bool item::conductive ( ) const

Whether the items is conductive.

Definition at line 6488 of file item.cpp.

6489{
6490 if( is_null() ) {
6491 return false;
6492 }
6493
6494 if( has_flag( flag_CONDUCTIVE ) ) {
6495 return true;
6496 }
6497
6498 if( has_flag( flag_NONCONDUCTIVE ) ) {
6499 return false;
6500 }
6501
6502 // If any material has electricity resistance equal to or lower than flesh (1) we are conductive.
6503 const std::vector<const material_type *> &mats = made_of_types();
6504 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6505 return mt->elec_resist() <= 1;
6506 } );
6507}
static const std::string flag_CONDUCTIVE("CONDUCTIVE")
static const std::string flag_NONCONDUCTIVE("NONCONDUCTIVE")

References flag_CONDUCTIVE(), flag_NONCONDUCTIVE(), has_flag(), is_null(), and made_of_types().

Referenced by Character::block_hit(), final_info(), and mdefense::zapback().

◆ contain_monster()

int item::contain_monster ( const tripoint target)

Definition at line 9218 of file iuse.cpp.

9219{
9220 const monster *const mon_ptr = g->critter_at<monster>( target );
9221 if( !mon_ptr ) {
9222 return 0;
9223 }
9224 const monster &f = *mon_ptr;
9225
9226 set_var( "contained_json", ::serialize( f ) );
9227 set_var( "contained_name", f.type->nname() );
9228 set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
9229 f.type->nname() ) );
9230 // Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
9231 set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
9232 g->remove_zombie( f );
9233 return 0;
9234}
void serialize(JsonOut &json) const
const mtype * type
Definition: monster.h:478
units::mass get_weight() const override
Definition: monster.cpp:2739
constexpr value_type to_milligram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:62
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:936
std::string nname(unsigned int quantity) const
Definition: itype.cpp:78
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, g, monster::get_weight(), itype::nname(), mtype::nname(), serialize(), set_var(), string_format(), units::to_milligram(), type, monster::type, and itype::weight.

Referenced by iuse::capture_monster_act().

◆ container_info()

void item::container_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3056 of file item.cpp.

3058{
3059 if( !is_container() || !parts->test( iteminfo_parts::CONTAINER_DETAILS ) ) {
3060 return;
3061 }
3062
3064 const islot_container &c = *type->container;
3065
3066 std::string container_str = _( "This container " );
3067
3068 if( c.seals ) {
3069 container_str += _( "can be <info>resealed</info>, " );
3070 }
3071 if( c.watertight ) {
3072 container_str += _( "is <info>watertight</info>, " );
3073 }
3074 if( c.preserves ) {
3075 container_str += _( "<good>prevents spoiling</good>, " );
3076 }
3077
3078 container_str += string_format( _( "can store <info>%s %s</info>." ),
3079 format_volume( c.contains ), volume_units_long() );
3080
3081 info.push_back( iteminfo( "CONTAINER", container_str ) );
3082}
bool is_container() const
Whether this is container.
Definition: item.cpp:6729
std::string format_volume(const units::volume &volume)
Convert, round up and format a volume.
Definition: output.cpp:2020
const char * volume_units_long()
Create a units label for a volume value.

References _, c, itype::container, CONTAINER_DETAILS, format_volume(), info(), insert_separation_line(), is_container(), string_format(), iteminfo_query::test(), type, and volume_units_long().

Referenced by info().

◆ contents_info()

void item::contents_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3565 of file item.cpp.

3567{
3569 return;
3570 }
3571 const std::string space = " ";
3572
3573 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
3574 std::string mod_str;
3575 if( mod->type->gunmod ) {
3576 if( mod->is_irremovable() ) {
3577 mod_str = _( "Integrated mod: " );
3578 } else {
3579 mod_str = _( "Mod: " );
3580 }
3581 mod_str += string_format( "<bold>%s</bold> (%s) ", mod->tname(),
3582 mod->type->gunmod->location.name() );
3583 }
3585 info.emplace_back( "DESCRIPTION", mod_str );
3586 info.emplace_back( "DESCRIPTION", mod->type->description.translated() );
3587 }
3588 bool contents_header = false;
3589 for( const item *contents_item : contents.all_items_top() ) {
3590 if( !contents_item->type->mod ) {
3591 if( !contents_header ) {
3593 info.emplace_back( "DESCRIPTION", _( "<bold>Contents of this item</bold>:" ) );
3594 contents_header = true;
3595 } else {
3596 // Separate items with a blank line
3597 info.emplace_back( "DESCRIPTION", space );
3598 }
3599
3600 const translation &description = contents_item->type->description;
3601
3602 if( contents_item->made_of( LIQUID ) ) {
3603 units::volume contents_volume = contents_item->volume() * batch;
3604 int converted_volume_scale = 0;
3605 const double converted_volume =
3606 round_up( convert_volume( contents_volume.value(),
3607 &converted_volume_scale ), 2 );
3608 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3610 if( display_mod_source ) {
3611 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3612 enumerate_as_string( contents_item->type->src.begin(),
3613 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3614 return string_format( "'%s'", content_source.second->name() );
3616 }
3617 if( display_object_ids ) {
3618 info.emplace_back( "DESCRIPTION", colorize(
3619 string_format( "[%s]", contents_item->type->get_id() ),
3620 c_light_blue ) );
3621 }
3622 if( converted_volume_scale != 0 ) {
3624 }
3625 info.emplace_back( "CONTAINER", description + space,
3626 string_format( "<num> %s", volume_units_abbr() ), f,
3627 converted_volume );
3628 } else {
3629 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3630 if( display_mod_source ) {
3631 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3632 enumerate_as_string( contents_item->type->src.begin(),
3633 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3634 return string_format( "'%s'", content_source.second->name() );
3636 }
3637 if( display_object_ids ) {
3638 info.emplace_back( "DESCRIPTION", colorize(
3639 string_format( "[%s]", contents_item->type->get_id() ),
3640 c_light_blue ) );
3641 }
3642 info.emplace_back( "DESCRIPTION", description.translated() );
3643 }
3644 }
3645 }
3646}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
constexpr const value_type & value() const
Access the raw dimensionless value.
Definition: units_def.h:44

References _, item_contents::all_items_top(), arrow, c_light_blue, colorize(), contents, convert_volume(), DESCRIPTION_CONTENTS, display_mod_source, display_object_ids, item_contents::empty(), enumerate_as_string(), gunmods(), info(), insert_separation_line(), iteminfo::is_decimal, is_gun(), LIQUID, iteminfo::no_newline, round_up(), sign::space, string_format(), iteminfo_query::test(), toolmods(), translation::translated(), units::quantity< V, U >::value(), and volume_units_abbr().

Referenced by info().

◆ contents_made_of()

bool item::contents_made_of ( phase_id  phase) const

If contents nonempty, return true if item phase is same, else false.

Definition at line 6475 of file item.cpp.

6476{
6477 return !contents.empty() && contents.front().made_of( phase );
6478}

References contents, item_contents::empty(), item_contents::front(), and made_of().

Referenced by character_funcs::find_ammo_helper().

◆ contextualize_skill()

skill_id item::contextualize_skill ( const skill_id id) const

Puts the skill in context of the item.

Definition at line 9973 of file item.cpp.

9974{
9975 if( id->is_contextual_skill() ) {
9976 if( id == skill_weapon ) {
9977 if( is_gun() ) {
9978 return gun_skill();
9979 } else if( is_melee() ) {
9980 return melee_skill();
9981 }
9982 }
9983 }
9984
9985 return id;
9986}
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7197
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7205
bool is_melee() const
Is this item an effective melee weapon for any damage type?
Definition: item.cpp:6677
static const skill_id skill_weapon("weapon")
const std::string id
Definition: basecamp.h:87

References gun_skill(), base_camps::id, is_gun(), is_melee(), melee_skill(), and skill_weapon.

Referenced by Character::enumerate_unmet_requirements(), and SkillLevelMap::get_skill_level().

◆ convert()

◆ corpse_volume()

units::volume item::corpse_volume ( const mtype corpse) const

Volume check for corpses, helper for base_volume().

Definition at line 5081 of file item.cpp.

5082{
5084 if( has_flag( flag_QUARTERED ) ) {
5085 corpse_volume /= 4;
5086 }
5088 corpse_volume *= 0.75;
5089 }
5090 if( has_flag( flag_GIBBED ) ) {
5091 corpse_volume *= 0.85;
5092 }
5093 if( has_flag( flag_SKINNED ) ) {
5094 corpse_volume *= 0.85;
5095 }
5096 if( corpse_volume > 0_ml ) {
5097 return corpse_volume;
5098 }
5099 debugmsg( "invalid monster volume for corpse" );
5100 return 0_ml;
5101}
static const std::string flag_GIBBED("GIBBED")
units::volume volume
Definition: mtype.h:264

References corpse, corpse_volume(), debugmsg, flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), and mtype::volume.

Referenced by base_volume(), corpse_volume(), and volume().

◆ count()

◆ count_by_charges() [1/2]

bool item::count_by_charges ( ) const

Definition at line 6015 of file item.cpp.

6016{
6017 return type->count_by_charges();
6018}

References itype::count_by_charges(), and type.

Referenced by activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), item_stack::amount_can_fit(), base_volume(), basic_info(), burn(), Character::can_eat(), repair_item_actor::can_repair_target(), charges_of_internal(), charges_per_volume(), craft_command::check_item_components_missing(), complete_craft(), crafting::complete_disassemble(), player::consume_items(), count(), craft_has_charges(), recipe::create_byproducts(), recipe::create_results(), display_name(), display_stacked_with(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), mattack::eat_food(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), iuse_transform::finalize(), emit_actor::finalize(), for_each_item_in_both(), Character::get_acquirable_energy(), recipe::get_consistency_error(), requirement_data::get_folded_list(), iexamine::get_harvest_items(), monexamine::give_items_to(), repair_item_actor::handle_components(), item_comp::has(), talk_function::individual_mission(), io(), repair_inventory_preset::is_shown(), merge_charges(), to_cbc_migration::migration_required(), mod_charges(), mod_damage(), Item_modifier::modify(), advanced_inventory::move_all_items(), move_item(), npc_throw(), pickup::obtain_and_tokenize_items(), pick_one_up(), pickup::pick_up(), activity_handlers::plant_seed_finish(), price(), advanced_inventory::query_charges(), vehicle::reload_seeds(), player::select_item_component(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), simulate_burn(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::throw_range(), ranged::throwing_dispersion(), npc_trading::trade(), try_consume(), units_remaining(), units_sufficient(), inventory::update_quality_cache(), use_charges(), volume(), weight(), Character::weight_carried_reduced_by(), and debug_menu::wishitem().

◆ count_by_charges() [2/2]

bool item::count_by_charges ( const itype_id id)
static

Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance.

Definition at line 9934 of file item.cpp.

9935{
9936 return id->count_by_charges();
9937}

◆ covers() [1/2]

◆ covers() [2/2]

bool item::covers ( const bodypart_id bp) const

Definition at line 753 of file item.cpp.

754{
755 return get_covered_body_parts().test( bp->token );
756}
bool test(const body_part &bp) const
Definition: bodypart.h:253

References get_covered_body_parts(), and body_part_set::test().

◆ craft_has_charges()

bool item::craft_has_charges ( )

Definition at line 6025 of file item.cpp.

6026{
6027 if( count_by_charges() ) {
6028 return true;
6029 } else if( ammo_types().empty() ) {
6030 return true;
6031 }
6032
6033 return false;
6034}

References ammo_types(), and count_by_charges().

Referenced by crafting::complete_disassemble(), and recipe::create_byproducts().

◆ cut_resist()

int item::cut_resist ( bool  to_self = false) const

Definition at line 6069 of file item.cpp.

6070{
6071 if( is_null() ) {
6072 return 0;
6073 }
6074
6075 const int base_thickness = get_thickness();
6076 float resist = 0;
6078 int eff_thickness = 1;
6079
6080 // base resistance
6081 // Don't give reinforced items +armor, just more resistance to ripping
6082 const int dmg = damage_level( 4 );
6083 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6084 eff_thickness = std::max( 1, base_thickness - eff_damage );
6085
6086 const std::vector<const material_type *> mat_types = made_of_types();
6087 if( !mat_types.empty() ) {
6088 for( const material_type *mat : mat_types ) {
6089 resist += mat->cut_resist();
6090 }
6091 // Average based on number of materials.
6092 resist /= mat_types.size();
6093 }
6094
6095 return std::lround( ( resist * eff_thickness ) + mod );
6096}
@ clothing_mod_type_cut
Definition: clothing_mod.h:20

References clothing_mod_type_cut, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), stab_resist(), and sew_advanced_actor::use().

◆ damage()

◆ damage_color()

nc_color item::damage_color ( ) const

Provide color for UI display dependent upon current item damage level.

Definition at line 6273 of file item.cpp.

6274{
6275 // TODO: unify with veh_interact::countDurability
6276 switch( damage_level( 4 ) ) {
6277 default:
6278 // reinforced
6279 if( damage() <= min_damage() ) {
6280 // fully reinforced
6281 return c_green;
6282 } else {
6283 return c_light_green;
6284 }
6285 case 0:
6286 return c_light_green;
6287 case 1:
6288 return c_yellow;
6289 case 2:
6290 return c_magenta;
6291 case 3:
6292 return c_light_red;
6293 case 4:
6294 if( damage() >= max_damage() ) {
6295 return c_dark_gray;
6296 } else {
6297 return c_red;
6298 }
6299 }
6300}
int min_damage() const
Minimum amount of damage to an item (state of maximum repair)
Definition: item.cpp:6221

References c_dark_gray, c_green, c_light_green, c_light_red, c_magenta, c_red, c_yellow, damage(), damage_level(), max_damage(), and min_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ damage_level()

int item::damage_level ( int  max) const

Scale item damage to the given number of levels.

This function is here mostly for back-compatibility. It should not be used when doing continuous math with the damage value: use damage() instead.

For example, for max = 4, min_damage = -1000, max_damage = 4000 damage level -1000 ~ -1 -1 0 0 1 ~ 1333 1 1334 ~ 2666 2 2667 ~ 3999 3 4000 4

Parameters
maxMaximum number of levels

Definition at line 706 of file item.cpp.

707{
708 if( damage_ == 0 || max <= 0 ) {
709 return 0;
710 } else if( max_damage() <= 1 ) {
711 return damage_ > 0 ? max : damage_;
712 } else if( damage_ < 0 ) {
713 return -( ( max - 1 ) * ( -damage_ - 1 ) / ( max_damage() - 1 ) + 1 );
714 } else {
715 return ( max - 1 ) * ( damage_ - 1 ) / ( max_damage() - 1 ) + 1;
716 }
717}

References damage_, and max_damage().

Referenced by Character::armor_absorb(), bash_resist(), bullet_resist(), activity_handlers::butcher_finish(), butchery_drops_harvest(), iuse::chainsaw_off(), crafting::complete_disassemble(), iuse::cs_lajatang_off(), cut_resist(), salvage_actor::cut_up(), damage_color(), vehicle_part::damage_level(), damage_melee(), damage_symbol(), veh_interact::do_repair(), durability_indicator(), gun_damage(), gun_dispersion(), avatar_funcs::gunmod_installation_odds(), monster::init_from_item(), vehicle_part::properties_to_item(), ready_to_revive(), repair_item_actor::repair_chance(), game::save_cyborg(), iuse::trimmer_off(), and fireweapon_off_actor::use().

◆ damage_melee()

int item::damage_melee ( damage_type  dt) const

Damage of given type caused when this item is used as melee weapon.

Definition at line 5215 of file item.cpp.

5216{
5217 assert( dt >= DT_NULL && dt < NUM_DT );
5218 if( is_null() ) {
5219 return 0;
5220 }
5221
5222 // effectiveness is reduced by 10% per damage level
5223 int res = type->melee[ dt ];
5224 res -= res * std::max( damage_level( 4 ), 0 ) * 0.1;
5225
5226 // apply type specific flags
5227 switch( dt ) {
5228 case DT_BASH:
5230 res *= 0.5;
5231 }
5232 break;
5233
5234 case DT_CUT:
5235 case DT_STAB:
5236 if( has_flag( flag_DIAMOND ) ) {
5237 res *= 1.3;
5238 }
5239 break;
5240
5241 default:
5242 break;
5243 }
5244
5245 // consider any melee gunmods
5246 if( is_gun() ) {
5247 const std::vector<const item *> &mods = gunmods();
5248 return std::accumulate( mods.begin(), mods.end(), res, [dt]( int last_max, const item * it ) {
5249 return it->has_flag( flag_MELEE_GUNMOD ) ? std::max( last_max, it->damage_melee( dt ) ) : last_max;
5250 } );
5251
5252 }
5253
5254 switch( dt ) {
5255 case DT_BASH:
5257 break;
5258 case DT_CUT:
5260 break;
5261 case DT_STAB:
5263 break;
5264 default:
5265 break;
5266 }
5267
5268 return std::max( res, 0 );
5269}
static const std::string flag_DIAMOND("DIAMOND")
static const std::string flag_REDUCED_BASHING("REDUCED_BASHING")
std::array< int, NUM_DT > melee
Damage output in melee for zero or more damage types.
Definition: itype.h:965

References bonus_from_enchantments_wielded(), damage_level(), DT_BASH, DT_CUT, DT_NULL, DT_STAB, flag_DIAMOND(), flag_REDUCED_BASHING(), gunmods(), has_flag(), is_gun(), is_null(), enchant_vals::ITEM_DAMAGE_BASH, enchant_vals::ITEM_DAMAGE_CUT, enchant_vals::ITEM_DAMAGE_STAB, itype::melee, NUM_DT, and type.

Referenced by base_damage_melee(), combat_info(), weapon_inventory_preset::deals_melee_damage(), character_effects::intimidation(), is_melee(), ma_requirements::is_valid_weapon(), melee_skill(), Character::melee_special_effects(), melee_train(), Character::power_rating(), activity_handlers::pulp_do_turn(), Character::reach_attack(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), smash(), and npc::smash_ability().

◆ damage_resist()

int item::damage_resist ( damage_type  dt,
bool  to_self = false 
) const

Resistance provided by this item against damage type given by an enum.

Definition at line 6381 of file item.cpp.

6382{
6383 switch( dt ) {
6384 case DT_NULL:
6385 case NUM_DT:
6386 return 0;
6387 case DT_TRUE:
6388 case DT_BIOLOGICAL:
6389 case DT_ELECTRIC:
6390 case DT_COLD:
6391 // Currently hardcoded:
6392 // Items can never be damaged by those types
6393 // But they provide 0 protection from them
6394 return to_self ? INT_MAX : 0;
6395 case DT_BASH:
6396 return bash_resist( to_self );
6397 case DT_CUT:
6398 return cut_resist( to_self );
6399 case DT_ACID:
6400 return acid_resist( to_self );
6401 case DT_STAB:
6402 return stab_resist( to_self );
6403 case DT_HEAT:
6404 return fire_resist( to_self );
6405 case DT_BULLET:
6406 return bullet_resist( to_self );
6407 default:
6408 debugmsg( "Invalid damage type: %d", dt );
6409 }
6410
6411 return 0;
6412}
int stab_resist(bool to_self=false) const
Definition: item.cpp:6102
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_TRUE
Definition: damage.h:22
@ DT_ACID
Definition: damage.h:26
@ DT_BULLET
Definition: damage.h:31
@ DT_BIOLOGICAL
Definition: damage.h:23
@ DT_HEAT
Definition: damage.h:28

References acid_resist(), bash_resist(), bullet_resist(), cut_resist(), debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, fire_resist(), NUM_DT, and stab_resist().

Referenced by Character::armor_absorb(), and resistances::resistances().

◆ damage_symbol()

std::string item::damage_symbol ( ) const

Provide prefix symbol for UI display dependent upon current item damage level.

Definition at line 6302 of file item.cpp.

6303{
6304 switch( damage_level( 4 ) ) {
6305 default:
6306 // reinforced
6307 return _( R"(++)" );
6308 case 0:
6309 return _( R"(||)" );
6310 case 1:
6311 return _( R"(|\)" );
6312 case 2:
6313 return _( R"(|.)" );
6314 case 3:
6315 return _( R"(\.)" );
6316 case 4:
6317 if( damage() >= max_damage() ) {
6318 return _( R"(XX)" );
6319 } else {
6320 return _( R"(..)" );
6321 }
6322
6323 }
6324}

References _, damage(), damage_level(), and max_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ deactivate()

item & item::deactivate ( const Character ch = nullptr,
bool  alert = true 
)

Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op.

Parameters
chcharacter currently possessing or acting upon the item (if any)
alertwhether to display any messages
Returns
same instance to allow method chaining

Definition at line 545 of file item.cpp.

546{
547 if( !active ) {
548 return *this; // no-op
549 }
550
551 if( is_tool() && type->tool->revert_to ) {
552 if( ch && alert && !type->tool->revert_msg.empty() ) {
553 ch->add_msg_if_player( m_info, _( type->tool->revert_msg ), tname() );
554 }
555 convert( *type->tool->revert_to );
556 active = false;
557
558 }
559 return *this;
560}
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:605
item & convert(const itype_id &new_type)
Filter converting this instance to another type preserving all other aspects.
Definition: item.cpp:538
@ m_info
Definition: enums.h:265

References _, active, Creature::add_msg_if_player(), alert, convert(), is_tool(), m_info, tname(), itype::tool, and type.

Referenced by iuse::note_bionics(), process_tool(), and fireweapon_on_actor::use().

◆ deserialize()

void item::deserialize ( JsonIn jsin)

Definition at line 2368 of file savegame_json.cpp.

2369{
2370 const JsonObject data = jsin.get_object();
2371 data.allow_omitted_members();
2372 io::JsonObjectInputArchive archive( data );
2373 io( archive );
2374 // made for fast forwarding time from 0.D to 0.E
2375 if( savegame_loading_version < 27 ) {
2377 }
2378 if( data.has_array( "contents" ) ) {
2379 std::list<item> items;
2380 data.read( "contents", items );
2381 contents = item_contents( items );
2382 } else {
2383 data.read( "contents", contents );
2384 }
2385
2386 // Sealed item migration: items with "unseals_into" set should always have contents
2388 convert( type->container->unseals_into );
2389 }
2390}
JsonObject get_object()
Definition: json.cpp:1432
bool has_array(const std::string &name) const
Definition: json.cpp:483
void allow_omitted_members() const
Definition: json.cpp:151
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
Input archive reading data from a Json object.
Definition: cata_io.h:185
void io(Archive &)
bool is_non_resealable_container() const
Whether removing this item's contents will permanently alter it.
Definition: item.cpp:6739
void legacy_fast_forward_time()
Definition: item.cpp:10022
int savegame_loading_version
Definition: savegame.cpp:64

References JsonObject::allow_omitted_members(), itype::container, contents, convert(), item_contents::empty(), JsonIn::get_object(), JsonObject::has_array(), io(), is_non_resealable_container(), legacy_fast_forward_time(), JsonObject::read(), savegame_loading_version, and type.

Referenced by item::craft_data::deserialize(), inventory::json_load_items(), monster::load(), and release_monster().

◆ destroyed_at_zero_charges()

bool item::destroyed_at_zero_charges ( ) const

Definition at line 6522 of file item.cpp.

6523{
6524 return ( is_ammo() || is_food() );
6525}

References is_ammo(), and is_food().

◆ detonate()

bool item::detonate ( const tripoint p,
std::vector< item > &  drops 
)

Detonates the item and adds remains (if any) to drops.

Returns true if the item actually detonated, potentially destroying other items and invalidating iterators. Should NOT be called on an item on the map, but on a local copy.

Definition at line 8755 of file item.cpp.

8756{
8757 if( type->explosion ) {
8759 return true;
8760 } else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8761 int charges_remaining = charges;
8762 const int rounds_exploded = rng( 1, charges_remaining );
8763 // Yank the exploding item off the map for the duration of the explosion
8764 // so it doesn't blow itself up.
8765 const islot_ammo &ammo_type = *type->ammo;
8766
8767 if( ammo_type.special_cookoff ) {
8768 // If it has a special effect just trigger it.
8769 apply_ammo_effects( p, ammo_type.ammo_effects, activated_by.get() );
8770 }
8771 charges_remaining -= rounds_exploded;
8772 if( charges_remaining > 0 ) {
8773 item temp_item = *this;
8774 temp_item.charges = charges_remaining;
8775 drops.push_back( temp_item );
8776 }
8777
8778 return true;
8779 } else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
8780 std::vector<item *> removed_items;
8781 bool detonated = false;
8782 for( item *it : contents.all_items_top() ) {
8783 if( it->detonate( p, drops ) ) {
8784 removed_items.push_back( it );
8785 detonated = true;
8786 }
8787 }
8788 for( item *it : removed_items ) {
8789 remove_item( *it );
8790 }
8791 return detonated;
8792 }
8793
8794 return false;
8795}
safe_reference< Character > activated_by
Definition: item.h:2248
void explosion(const tripoint &p, Creature *source, float power, float factor, bool fire, int legacy_casing_mass, float)
Legacy explosion function.
Definition: explosion.cpp:1080
void apply_ammo_effects(const tripoint &p, const std::set< ammo_effect_str_id > &effects, Creature *source)
Definition: projectile.cpp:110
explosion_data explosion
Definition: itype.h:916

References activated_by, item_contents::all_items_top(), itype::ammo, ammo_type(), apply_ammo_effects(), charges, contents, item_contents::empty(), explosion_handler::explosion(), itype::explosion, itype::magazine, visitable< item >::remove_item(), rng(), and type.

Referenced by map::process_fields_in_submap(), and map::smash_items().

◆ disassembly_info()

void item::disassembly_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3196 of file item.cpp.

3198{
3200 return;
3201 }
3203 return;
3204 }
3205
3207 const requirement_data &req = dis.disassembly_requirements();
3208 if( !req.is_empty() ) {
3209 const std::string approx_time = to_string_approx( time_duration::from_turns( dis.time / 100 ) );
3210
3212 const std::string comps_str = enumerate_as_string( comps_list.begin(), comps_list.end(),
3213 []( const std::vector<item_comp> &comp_opts ) {
3214 return comp_opts.front().to_string();
3215 } );
3216
3217 std::vector<std::string> reqs_list;
3218 const requirement_data::alter_tool_comp_vector &tools_list = req.get_tools();
3219 for( const std::vector<tool_comp> &it : tools_list ) {
3220 if( !it.empty() ) {
3221 reqs_list.push_back( it.front().to_string() );
3222 }
3223 }
3225 for( const std::vector<quality_requirement> &it : quals_list ) {
3226 if( !it.empty() ) {
3227 reqs_list.push_back( it.front().to_colored_string() );
3228 }
3229 }
3230
3231 std::string descr;
3232 if( reqs_list.empty() ) {
3233 //~ 1 is approx. time (e.g. 'about 5 minutes'), 2 is a list of items
3234 descr = string_format( _( "<bold>Disassembly</bold> takes %1$s and might yield: %2$s." ),
3235 approx_time, comps_str );
3236 } else {
3237 const std::string reqs_str = enumerate_as_string( reqs_list );
3238 descr = string_format(
3239 //~ 1 is approx. time, 2 is a list of items and tools with qualities, 3 is a list of items.
3240 //~ Bold text in the middle makes it easier to see where the second list starts.
3241 _( "<bold>Disassembly</bold> takes %1$s, requires %2$s and <bold>might yield</bold>: %3$s." ),
3242 approx_time, reqs_str, comps_str );
3243 }
3244
3246 info.push_back( iteminfo( "DESCRIPTION", descr ) );
3247 }
3248}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
Definition: recipe.h:35
requirement_data disassembly_requirements() const
If recipe can be used for disassembly fetch the combined requirements.
Definition: recipe.h:96
int time
Definition: recipe.h:61
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DESCRIPTION_COMPONENTS_DISASSEMBLE
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_tool_comp_vector & get_tools() const
const alter_item_comp_vector & get_components() const
std::vector< std::vector< quality_requirement > > alter_quali_req_vector
Definition: requirements.h:222
bool is_empty() const
empty requirements are not necessary null
Definition: requirements.h:247
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223
const alter_quali_req_vector & get_qualities() const
std::vector< std::vector< tool_comp > > alter_tool_comp_vector
Definition: requirements.h:221

References _, components, DESCRIPTION_COMPONENTS_DISASSEMBLE, DESCRIPTION_COMPONENTS_MADEFROM, recipe::disassembly_requirements(), enumerate_as_string(), time_duration::from_turns(), requirement_data::get_components(), requirement_data::get_qualities(), requirement_data::get_tools(), recipe_dictionary::get_uncraft(), info(), insert_separation_line(), requirement_data::is_empty(), string_format(), iteminfo_query::test(), recipe::time, to_string_approx(), and typeId().

Referenced by info().

◆ display_money()

std::string item::display_money ( unsigned int  quantity,
unsigned int  total,
const std::optional< unsigned int > &  selected = std::nullopt 
) const

Definition at line 4826 of file item.cpp.

4828{
4829 if( selected ) {
4830 //~ This is a string to display the selected and total amount of money in a stack of cash cards.
4831 //~ %1$s is the display name of cash cards.
4832 //~ %2$s is the total amount of money.
4833 //~ %3$s is the selected amount of money.
4834 //~ Example: "cash cards $15.35 of $20.48"
4835 return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ),
4836 format_money( total ), format_money( *selected ) );
4837 } else {
4838 //~ This is a string to display the total amount of money in a stack of cash cards.
4839 //~ %1$s is the display name of cash cards.
4840 //~ %2$s is the total amount of money on the cash cards.
4841 //~ Example: "cash cards $20.48"
4842 return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ),
4843 format_money( total ) );
4844 }
4845}
std::string format_money(int cents)
Definition: output.h:932
const char * pgettext(const char *context, const char *msgid)

References format_money(), pgettext(), string_format(), and tname().

Referenced by inventory_selector_preset::get_caption(), and selection_column_preset::get_caption().

◆ display_name()

std::string item::display_name ( unsigned int  quantity = 1) const

Returns the item name and the charges or contained charges (if the item can have charges at all).

Calls tname with given quantity and with_prefix being true.

Definition at line 4847 of file item.cpp.

4848{
4849 std::string name = tname( quantity );
4850 std::string sidetxt;
4851 std::string amt;
4852
4853 switch( get_side() ) {
4854 case side::BOTH:
4855 case side::num_sides:
4856 break;
4857 case side::LEFT:
4858 sidetxt = string_format( " (%s)", _( "left" ) );
4859 break;
4860 case side::RIGHT:
4861 sidetxt = string_format( " (%s)", _( "right" ) );
4862 break;
4863 }
4864 avatar &you = get_avatar();
4865 int amount = 0;
4866 int max_amount = 0;
4867 bool has_item = is_container() && contents.num_item_stacks() == 1;
4868 bool has_ammo = is_ammo_container() && contents.num_item_stacks() == 1;
4869 bool contains = has_item || has_ammo;
4870 bool show_amt = false;
4871 // We should handle infinite charges properly in all cases.
4872 if( contains ) {
4873 amount = contents.front().charges;
4875 } else if( is_book() && get_chapters() > 0 ) {
4876 // a book which has remaining unread chapters
4877 amount = get_remaining_chapters( you );
4878 } else if( ammo_capacity() > 0 ) {
4879 // anything that can be reloaded including tools, magazines, guns and auxiliary gunmods
4880 // but excluding bows etc., which have ammo, but can't be reloaded
4881 amount = ammo_remaining();
4882 max_amount = ammo_capacity();
4883 show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
4884 } else if( count_by_charges() && !has_infinite_charges() ) {
4885 // A chargeable item
4886 amount = charges;
4887 max_amount = ammo_capacity();
4888 } else if( is_battery() ) {
4889 show_amt = true;
4890 amount = to_joule( energy_remaining() );
4891 max_amount = to_joule( type->battery->max_capacity );
4892 }
4893
4894 std::string ammotext;
4895 if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
4896 if( !ammo_current().is_null() ) {
4897 ammotext = ammo_current()->nname( 1 );
4898 } else {
4899 ammotext = ammotype( *ammo_types().begin() )->name();
4900 }
4901 }
4902
4903 if( amount || show_amt ) {
4904 if( is_money() ) {
4905 amt = string_format( " $%.2f", amount / 100.0 );
4906 } else {
4907 if( !ammotext.empty() ) {
4908 ammotext = " " + ammotext;
4909 }
4910
4911 if( max_amount != 0 ) {
4912 amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
4913 } else {
4914 amt = string_format( " (%i%s)", amount, ammotext );
4915 }
4916 }
4917 } else if( !ammotext.empty() ) {
4918 amt = " (" + ammotext + ")";
4919 }
4920
4921 // HACK: This is a hack to prevent possible crashing when displaying maps as items during character creation
4923 // TODO: fix point types
4924 tripoint map_pos_omt =
4925 get_var( "reveal_map_center_omt", you.global_omt_location().raw() );
4926 tripoint_abs_sm map_pos =
4927 project_to<coords::sm>( tripoint_abs_omt( map_pos_omt ) );
4928 const city *c = overmap_buffer.closest_city( map_pos ).city;
4929 if( c != nullptr ) {
4930 name = string_format( "%s %s", c->name, name );
4931 }
4932 }
4933
4934 return string_format( "%s%s%s", name, sidetxt, amt );
4935}
@ num_sides
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6275
constexpr Point & raw()
Definition: coordinates.h:111
bool is_ammo_container() const
Definition: item.cpp:6672
bool has_infinite_charges() const
Definition: item.cpp:9968
itype_id ammo_current() const
Specific ammo type, returns "null" if item is neither ammo nor loaded with any.
Definition: item.cpp:7561
bool is_map() const
Definition: item.cpp:6724
units::energy energy_remaining() const
Quantity of energy currently loaded in tool or battery.
Definition: item.cpp:7375
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:869
units::volume get_container_capacity() const
It returns the total capacity (volume) of the container for liquids.
Definition: item.cpp:8402
side get_side() const
Returns side item currently worn on.
Definition: item.cpp:813
int get_chapters() const
How many chapters the book has (if any).
Definition: item.cpp:7099
city_reference closest_city(const tripoint_abs_sm &center)
Find the closest city.
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:96
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
overmapbuffer overmap_buffer
const struct city * city
The city itself, points into overmap::cities.
Definition: overmapbuffer.h:81
Definition: overmap.h:55

References _, ammo_capacity(), ammo_current(), ammo_remaining(), ammo_required(), ammo_types(), itype::battery, BOTH, c, charges, charges_per_volume(), city_reference::city, overmapbuffer::closest_city(), contains, contents, count_by_charges(), energy_remaining(), flag_RELOAD_AND_SHOOT(), item_contents::front(), get_avatar(), get_chapters(), get_container_capacity(), get_remaining_chapters(), get_side(), get_var(), Character::global_omt_location(), has_flag(), has_infinite_charges(), visitable< item >::has_item(), is_ammo_container(), is_battery(), is_book(), is_container(), is_gun(), is_magazine(), is_map(), is_money(), is_null(), LEFT, ammunition_type::name(), om_direction::name(), itype::nname(), item_contents::num_item_stacks(), num_sides, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), RIGHT, string_format(), tname(), units::to_joule(), calendar::turn, calendar::turn_zero, and type.

Referenced by act_vehicle_unload_fuel(), monexamine::add_armor(), monexamine::attach_bag_to(), veh_interact::can_remove_part(), game_menus::inv::container_for(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), liquid_handler::get_liquid_target(), game::handle_action(), handle_problematic_pickup(), pickup::handle_spillable_contents(), inscribe_actor::item_inscription(), game::list_items(), pick_one_up(), pickup::pick_up(), trading_window::update_win(), and musical_instrument_actor::use().

◆ display_stacked_with()

bool item::display_stacked_with ( const item rhs,
bool  check_components = false 
) const

Whether two items should stack when displayed in a inventory menu.

This is different from stacks_with, when two previously non-stackable items are now stackable and mergeable because, for example, they reaches the same temperature. This is necessary to avoid misleading stacks like "3 items-count-by-charge (5)".

Definition at line 889 of file item.cpp.

890{
891 return !count_by_charges() && stacks_with( rhs, check_components );
892}
bool stacks_with(const item &rhs, bool check_components=false, bool skip_type_check=false) const
Definition: item.cpp:894

References count_by_charges(), and stacks_with().

Referenced by pickup::stack_for_pickup_ui().

◆ dps() [1/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc 
) const

Definition at line 1448 of file item.cpp.

1449{
1450 return dps( for_display, for_calc, get_avatar() );
1451}

References dps(), and get_avatar().

◆ dps() [2/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc,
const player guy 
) const

calculate effective dps against a stock set of monsters.

by default, assume g->u is wielding for_display - include monsters intended for display purposes for_calc - include monsters intended for evaluation purposes for_display and for_calc are inclusive

Definition at line 1433 of file item.cpp.

1435{
1436 std::map<std::string, double> results;
1437 for( const std::pair<translation, dps_comp_data> &comp_mon : dps_comp_monsters ) {
1438 if( ( comp_mon.second.display != for_display ) &&
1439 ( comp_mon.second.evaluate != for_calc ) ) {
1440 continue;
1441 }
1442 monster test_mon = monster( comp_mon.second.mon_id );
1443 results[ comp_mon.first.translated() ] = effective_dps( guy, test_mon );
1444 }
1445 return results;
1446}
double effective_dps(const player &guy, const monster &mon) const
Calculate the item's effective damage per second past armor when wielded by a character against a mon...
Definition: item.cpp:1330
static const std::vector< std::pair< translation, dps_comp_data > > dps_comp_monsters
Definition: item.cpp:1426

References dps_comp_monsters, and effective_dps().

Referenced by average_dps(), combat_info(), dps(), and ideal_ranged_dps().

◆ durability_indicator()

std::string item::durability_indicator ( bool  include_intact = false) const

Provides a prefix for the durability state of the item.

with ITEM_HEALTH_BAR enabled, returns a symbol with color tag already applied. Otherwise, returns an adjective. if include_intact is true, this provides a string for the corner case of a player with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.

Definition at line 6326 of file item.cpp.

6327{
6328 std::string outputstring;
6329
6330 if( damage() < 0 ) {
6331 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6332 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6333 } else if( is_gun() ) {
6334 outputstring = pgettext( "damage adjective", "accurized " );
6335 } else {
6336 outputstring = pgettext( "damage adjective", "reinforced " );
6337 }
6338 } else if( has_flag( flag_CORPSE ) ) {
6339 if( damage() > 0 ) {
6340 switch( damage_level( 4 ) ) {
6341 case 1:
6342 outputstring = pgettext( "damage adjective", "bruised " );
6343 break;
6344 case 2:
6345 outputstring = pgettext( "damage adjective", "damaged " );
6346 break;
6347 case 3:
6348 outputstring = pgettext( "damage adjective", "mangled " );
6349 break;
6350 default:
6351 outputstring = pgettext( "damage adjective", "pulped " );
6352 break;
6353 }
6354 }
6355 } else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6356 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6357 } else {
6358 outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
6359 if( include_intact && outputstring == " " ) {
6360 outputstring = _( "fully intact " );
6361 }
6362 }
6363
6364 return outputstring;
6365}
std::string damage_symbol() const
Provide prefix symbol for UI display dependent upon current item damage level.
Definition: item.cpp:6302
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:7161
nc_color damage_color() const
Provide color for UI display dependent upon current item damage level.
Definition: item.cpp:6273

References _, colorize(), damage(), damage_color(), damage_level(), damage_symbol(), flag_CORPSE(), get_base_material(), has_flag(), is_gun(), pgettext(), and string_format().

Referenced by colorized_item_name(), damage_item(), iuse::gun_repair(), repair_item_actor::repair(), and tname().

◆ effective_dps()

double item::effective_dps ( const player guy,
const monster mon 
) const

Calculate the item's effective damage per second past armor when wielded by a character against a monster.

Definition at line 1330 of file item.cpp.

1331{
1332 const float mon_dodge = mon.get_dodge();
1333 float base_hit = guy.get_dex() / 4.0f + guy.get_hit_weapon( *this );
1334 base_hit *= std::max( 0.25f, 1.0f - guy.encumb( bp_torso ) / 100.0f );
1335 float mon_defense = mon_dodge + mon.size_melee_penalty() / 5.0;
1336 constexpr double hit_trials = 10000.0;
1337 const int rng_mean = std::max( std::min( static_cast<int>( base_hit - mon_defense ), 20 ),
1338 -20 ) + 20;
1339 double num_all_hits = hits_by_accuracy[ rng_mean ];
1340 /* critical hits have two chances to occur: triple critical hits happen much less frequently,
1341 * and double critical hits can only occur if a hit roll is more than 1.5 * monster dodge.
1342 * Not the hit roll used to determine the attack, another one.
1343 * the way the math works, some percentage of the total hits are eligible to be double
1344 * critical hits, and the rest are eligible to be triple critical hits, but in each case,
1345 * only some small percent of them actually become critical hits.
1346 */
1347 const int rng_high_mean = std::max( std::min( static_cast<int>( base_hit - 1.5 * mon_dodge ),
1348 20 ), -20 ) + 20;
1349 double num_high_hits = hits_by_accuracy[ rng_high_mean ] * num_all_hits / hit_trials;
1350 double double_crit_chance = guy.crit_chance( 4, 0, *this );
1351 double crit_chance = guy.crit_chance( 0, 0, *this );
1352 double num_low_hits = std::max( 0.0, num_all_hits - num_high_hits );
1353
1354 double moves_per_attack = guy.attack_cost( *this );
1355 // attacks that miss do no damage but take time
1356 double total_moves = ( hit_trials - num_all_hits ) * moves_per_attack;
1357 double total_damage = 0.0;
1358 double num_crits = std::min( num_low_hits * crit_chance + num_high_hits * double_crit_chance,
1359 num_all_hits );
1360 // critical hits are counted separately
1361 double num_hits = num_all_hits - num_crits;
1362 // sum average damage past armor and return the number of moves required to achieve
1363 // that damage
1364 const auto calc_effective_damage = [ &, moves_per_attack]( const double num_strikes,
1365 const bool crit, const player & guy, const monster & mon ) {
1366 monster temp_mon = mon;
1367 double subtotal_damage = 0;
1368 damage_instance base_damage;
1369 guy.roll_all_damage( crit, base_damage, true, *this );
1370 damage_instance dealt_damage = base_damage;
1371 temp_mon.absorb_hit( bodypart_id( "torso" ), dealt_damage );
1372 dealt_damage_instance dealt_dams;
1373 for( const damage_unit &dmg_unit : dealt_damage.damage_units ) {
1374 int cur_damage = 0;
1375 int total_pain = 0;
1376 temp_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1377 if( cur_damage > 0 ) {
1378 dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1379 }
1380 }
1381 double damage_per_hit = dealt_dams.total_damage();
1382 subtotal_damage = damage_per_hit * num_strikes;
1383 double subtotal_moves = moves_per_attack * num_strikes;
1384
1385 if( has_technique( rapid_strike ) ) {
1386 monster temp_rs_mon = mon;
1387 damage_instance rs_base_damage;
1388 guy.roll_all_damage( crit, rs_base_damage, true, *this );
1389 damage_instance dealt_rs_damage = rs_base_damage;
1390 for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1391 dmg_unit.damage_multiplier *= 0.66;
1392 }
1393 temp_rs_mon.absorb_hit( bodypart_id( "torso" ), dealt_rs_damage );
1394 dealt_damage_instance rs_dealt_dams;
1395 for( const damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1396 int cur_damage = 0;
1397 int total_pain = 0;
1398 temp_rs_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1399 if( cur_damage > 0 ) {
1400 rs_dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1401 }
1402 }
1403 double rs_damage_per_hit = rs_dealt_dams.total_damage();
1404 subtotal_moves *= 0.5;
1405 subtotal_damage *= 0.5;
1406 subtotal_moves += moves_per_attack * num_strikes * 0.33;
1407 subtotal_damage += rs_damage_per_hit * num_strikes * 0.5;
1408 }
1409 return std::make_pair( subtotal_moves, subtotal_damage );
1410 };
1411 std::pair<double, double> crit_summary = calc_effective_damage( num_crits, true, guy, mon );
1412 total_moves += crit_summary.first;
1413 total_damage += crit_summary.second;
1414 std::pair<double, double> summary = calc_effective_damage( num_hits, false, guy, mon );
1415 total_moves += summary.first;
1416 total_damage += summary.second;
1417 return total_damage * to_moves<double>( 1_seconds ) / total_moves;
1418}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:25
virtual int get_dex() const
Definition: character.cpp:4093
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:335
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4026
int size_melee_penalty() const
Definition: creature.cpp:484
bool has_technique(const matec_id &tech) const
Whether the item supports a specific martial art technique (either through its type,...
Definition: item.cpp:5466
void deal_damage_handle_type(const damage_unit &du, bodypart_id bp, int &damage, int &pain) override
Definition: monster.cpp:1626
float get_dodge() const override
Definition: monster.cpp:2007
void absorb_hit(const bodypart_id &bp, damage_instance &dam) override
Definition: monster.cpp:1409
Definition: player.h:84
static const double hits_by_accuracy[41]
Definition: item.cpp:1318
static const matec_id rapid_strike("RAPID")
damage_type type
Definition: damage.h:36
float damage_multiplier
Definition: damage.h:40
std::array< int, NUM_DT > dealt_dams
Definition: damage.h:86
int total_damage() const
Definition: damage.cpp:180

References monster::absorb_hit(), Character::attack_cost(), bp_torso, Character::crit_chance(), damage_unit::damage_multiplier, damage_instance::damage_units, monster::deal_damage_handle_type(), dealt_damage_instance::dealt_dams, Character::encumb(), Character::get_dex(), monster::get_dodge(), Character::get_hit_weapon(), has_technique(), hits_by_accuracy, rapid_strike, Character::roll_all_damage(), Creature::size_melee_penalty(), dealt_damage_instance::total_damage(), and damage_unit::type.

Referenced by dps().

◆ energy_remaining()

units::energy item::energy_remaining ( ) const

Quantity of energy currently loaded in tool or battery.

Definition at line 7375 of file item.cpp.

7376{
7377 if( is_battery() ) {
7378 return energy;
7379 }
7380
7381 return 0_J;
7382}
units::energy energy
Definition: item.h:2210

References energy, and is_battery().

Referenced by display_name(), mod_energy(), process_vehicle_items(), and charger_tile::update_internal().

◆ engine_displacement()

int item::engine_displacement ( ) const

for combustion engines the displacement (cc)

Definition at line 4139 of file item.cpp.

4140{
4141 return type->engine ? type->engine->displacement : 0;
4142}
cata::value_ptr< islot_engine > engine
Definition: itype.h:827

References itype::engine, and type.

Referenced by veh_interact::display_details(), vehicle_part::name(), vehicle::part_vpower_w(), and tname().

◆ erase_var()

void item::erase_var ( const std::string &  name)

◆ faults_potential()

std::set< fault_id > item::faults_potential ( ) const

What faults can potentially occur with this item?

Definition at line 6814 of file item.cpp.

6815{
6816 std::set<fault_id> res;
6817 res.insert( type->faults.begin(), type->faults.end() );
6818 return res;
6819}
std::set< fault_id > faults
What faults (if any) can occur.
Definition: itype.h:988

References itype::faults, and type.

Referenced by vehicle_part::faults_potential(), ranged::handle_gun_damage(), and examine_item_menu::rate_action_mend().

◆ fill_with()

void item::fill_with ( item liquid,
int  amount = INFINITE_CHARGES 
)

Fill item with liquid up to its capacity.

This works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to fill the container with.
amountAmount to fill item with, capped by remaining capacity

Definition at line 8569 of file item.cpp.

8570{
8571 amount = std::min( get_remaining_capacity_for_liquid( liquid, true ),
8572 std::min( amount, liquid.charges ) );
8573 if( amount <= 0 ) {
8574 return;
8575 }
8576
8577 if( !is_container() ) {
8578 if( !is_reloadable_with( liquid.typeId() ) ) {
8579 debugmsg( "Tried to fill %s which is not a container and can't be reloaded with %s.",
8580 tname(), liquid.tname() );
8581 return;
8582 }
8583 ammo_set( liquid.typeId(), ammo_remaining() + amount );
8584 } else if( is_food_container() ) {
8585 item &cts = contents.front();
8586 // Use maximum rot between the two
8587 cts.set_relative_rot( std::max( cts.get_relative_rot(),
8588 liquid.get_relative_rot() ) );
8589 cts.mod_charges( amount );
8590 } else if( !is_container_empty() ) {
8591 // if container already has liquid we need to set the amount
8592 item &cts = contents.front();
8593 cts.mod_charges( amount );
8594 } else {
8595 item liquid_copy( liquid );
8596 liquid_copy.charges = amount;
8597 put_in( liquid_copy );
8598 }
8599
8600 liquid.mod_charges( -amount );
8602}
bool is_reloadable_with(const itype_id &ammo) const
Returns true if this item can be reloaded with specified ammo type at this moment.
Definition: item.cpp:6881
void mod_charges(int mod)
Modify the charges of this item, only use for items counted by charges! The item must have enough cha...
Definition: item.cpp:9728
void on_contents_changed()
Callback when contents of the item are affected in any way other than just processing.
Definition: item.cpp:4560
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8431

References ammo_remaining(), ammo_set(), charges, contents, debugmsg, item_contents::front(), get_relative_rot(), get_remaining_capacity_for_liquid(), is_container(), is_container_empty(), is_food_container(), is_reloadable_with(), mod_charges(), on_contents_changed(), put_in(), set_relative_rot(), tname(), and typeId().

Referenced by veh_interact::complete_vehicle(), vehicle_part::fill_with(), advanced_inventory::move_content(), Character::pour_into(), and reload().

◆ final_info()

void item::final_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3648 of file item.cpp.

3650{
3651 if( is_null() ) {
3652 return;
3653 }
3654
3655 // TODO: Remove
3656 const iteminfo_query *parts = &parts_ref;
3657
3658 const std::string space = " ";
3659
3661
3662 if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
3663 if( !type->rigid ) {
3664 info.emplace_back( "BASE",
3665 _( "* This item is <info>not rigid</info>. Its"
3666 " volume and encumbrance increase with contents." ) );
3667 }
3668 }
3669
3671 if( !conductive() ) {
3672 info.push_back( iteminfo( "BASE", _( "* This item <good>does not "
3673 "conduct</good> electricity." ) ) );
3674 } else if( has_flag( flag_CONDUCTIVE ) ) {
3675 info.push_back( iteminfo( "BASE",
3676 _( "* This item effectively <bad>conducts</bad> "
3677 "electricity, as it has no guard." ) ) );
3678 } else {
3679 info.push_back( iteminfo( "BASE", _( "* This item <bad>conducts</bad> electricity." ) ) );
3680 }
3681 }
3682
3683 avatar &you = get_avatar();
3684 if( is_armor() && you.has_trait( trait_WOOLALLERGY ) &&
3685 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
3686 info.push_back( iteminfo( "DESCRIPTION",
3687 _( "* This clothing will give you an <bad>allergic "
3688 "reaction</bad>." ) ) );
3689 }
3690
3691 if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
3692 // concatenate base and acquired flags...
3693 std::vector<std::string> flags;
3694 std::set_union( type->get_flags().begin(), type->get_flags().end(),
3695 get_flags().begin(), get_flags().end(),
3696 std::back_inserter( flags ) );
3697
3698 // ...and display those which have an info description
3699 for( const std::string &e : flags ) {
3700 const json_flag &f = json_flag::get( e );
3701 if( !f.info().empty() ) {
3702 info.emplace_back( "DESCRIPTION", string_format( "* %s", _( f.info() ) ) );
3703 }
3704 }
3705 }
3706
3707 armor_fit_info( info, parts, batch, debug );
3708
3709 if( is_tool() ) {
3711 info.push_back( iteminfo( "DESCRIPTION",
3712 _( "* This tool can draw power from a <info>Bionic Armor Interface</info>" ) ) );
3713 }
3715 info.push_back( iteminfo( "DESCRIPTION",
3716 _( "* This tool uses a <info>universal power supply</info> "
3717 "and is <neutral>not compatible</neutral> with "
3718 "<info>standard batteries</info>." ) ) );
3719 } else if( has_flag( flag_RECHARGE ) && has_flag( flag_NO_RELOAD ) &&
3721 info.push_back( iteminfo( "DESCRIPTION",
3722 _( "* This tool has a <info>rechargeable power cell</info> "
3723 "and is <neutral>not compatible</neutral> with "
3724 "<info>standard batteries</info>." ) ) );
3725 } else if( has_flag( flag_RECHARGE ) &&
3727 info.push_back( iteminfo( "DESCRIPTION",
3728 _( "* This tool has a <info>rechargeable power cell</info> "
3729 "and can be recharged in any <neutral>UPS-compatible "
3730 "recharging station</neutral>. You could charge it with "
3731 "<info>standard batteries</info>, but unloading it is "
3732 "impossible." ) ) );
3733 } else if( has_flag( flag_USES_BIONIC_POWER ) ) {
3734 info.emplace_back( "DESCRIPTION",
3735 _( "* This tool <info>runs on bionic power</info>." ) );
3736 }
3737 }
3738
3741 if( has_flag( flag_RADIO_MOD ) ) {
3742 info.emplace_back( "DESCRIPTION",
3743 _( "* This item has been modified to listen to <info>radio "
3744 "signals</info>. It can still be activated manually." ) );
3745 } else {
3746 info.emplace_back( "DESCRIPTION",
3747 _( "* This item can only be activated by a <info>radio "
3748 "signal</info>." ) );
3749 }
3750
3751 std::string signame;
3752 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
3753 signame = "<color_c_red>red</color> radio signal.";
3754 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
3755 signame = "<color_c_blue>blue</color> radio signal.";
3756 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
3757 signame = "<color_c_green>green</color> radio signal.";
3758 }
3760 info.emplace_back( "DESCRIPTION",
3761 string_format( _( "* It will be activated by the %s." ),
3762 signame ) );
3763 }
3764
3767 info.emplace_back( "DESCRIPTION",
3768 _( "* Activating this item with a <info>radio signal</info> will "
3769 "<neutral>detonate</neutral> it immediately." ) );
3770 }
3771 }
3772
3773 bionic_info( info, parts, batch, debug );
3774
3775 if( is_gun() && has_flag( flag_FIRE_TWOHAND ) &&
3777 info.push_back( iteminfo( "DESCRIPTION",
3778 _( "* This weapon needs <info>two free hands</info> "
3779 "to fire." ) ) );
3780 }
3781
3784 info.push_back( iteminfo( "DESCRIPTION",
3785 _( "* This mod <bad>obscures sights</bad> of the "
3786 "base weapon." ) ) );
3787 }
3788
3789 if( is_gunmod() && has_flag( flag_CONSUMABLE ) &&
3791 info.push_back( iteminfo( "DESCRIPTION",
3792 _( "* This mod might <bad>suffer wear</bad> when firing "
3793 "the base weapon." ) ) );
3794 }
3795
3798 info.push_back( iteminfo( "DESCRIPTION",
3799 _( "* The casing of this item has <neutral>cracked</neutral>, "
3800 "revealing an <info>ominous green glow</info>." ) ) );
3801 }
3802
3805 info.push_back( iteminfo( "DESCRIPTION",
3806 _( "* This object is <neutral>surrounded</neutral> by a "
3807 "<info>sickly green glow</info>." ) ) );
3808 }
3809
3810 if( is_brewable() || ( !contents.empty() && contents.front().is_brewable() ) ) {
3811 const item &brewed = !is_brewable() ? contents.front() : *this;
3813 const time_duration btime = brewed.brewing_time();
3814 int btime_i = to_days<int>( btime );
3815 if( btime <= 2_days ) {
3816 btime_i = to_hours<int>( btime );
3817 info.push_back( iteminfo( "DESCRIPTION",
3818 string_format( vgettext( "* Once set in a vat, this "
3819 "will ferment in around %d hour.",
3820 "* Once set in a vat, this will ferment in "
3821 "around %d hours.", btime_i ), btime_i ) ) );
3822 } else {
3823 info.push_back( iteminfo( "DESCRIPTION",
3824 string_format( vgettext( "* Once set in a vat, this "
3825 "will ferment in around %d day.",
3826 "* Once set in a vat, this will ferment in "
3827 "around %d days.", btime_i ), btime_i ) ) );
3828 }
3829 }
3831 for( const itype_id &res : brewed.brewing_results() ) {
3832 info.push_back( iteminfo( "DESCRIPTION",
3833 string_format( _( "* Fermenting this will produce "
3834 "<neutral>%s</neutral>." ),
3835 nname( res, brewed.charges ) ) ) );
3836 }
3837 }
3838 }
3839
3841 for( const fault_id &e : faults ) {
3842 //~ %1$s is the name of a fault and %2$s is the description of the fault
3843 info.emplace_back( "DESCRIPTION", string_format( _( "* <bad>%1$s</bad>. %2$s" ),
3844 e.obj().name(), e.obj().description() ) );
3845 }
3846 }
3847
3848 // does the item fit in any holsters?
3849 std::vector<const itype *> holsters = item_controller->find( [this]( const itype & e ) {
3850 if( !e.can_use( "holster" ) ) {
3851 return false;
3852 }
3853 const holster_actor *ptr = dynamic_cast<const holster_actor *>
3854 ( e.get_use( "holster" )->get_actor_ptr() );
3855 return ptr->can_holster( *this );
3856 } );
3857
3858 if( !holsters.empty() && parts->test( iteminfo_parts::DESCRIPTION_HOLSTERS ) ) {
3860 info.emplace_back( "DESCRIPTION", _( "<bold>Can be stored in</bold>: " ) +
3861 enumerate_as_string( holsters.begin(), holsters.end(),
3862 []( const itype * e ) {
3863 return e->nname( 1 );
3864 } ) );
3865 }
3866
3868 for( auto &u : type->use_methods ) {
3869 const delayed_transform_iuse *tt = dynamic_cast<const delayed_transform_iuse *>
3870 ( u.second.get_actor_ptr() );
3871 if( tt == nullptr ) {
3872 continue;
3873 }
3874 const int time_to_do = tt->time_to_do( *this );
3875 if( time_to_do <= 0 ) {
3876 info.push_back( iteminfo( "DESCRIPTION",
3877 _( "It's done and <info>can be activated</info>." ) ) );
3878 } else {
3879 const std::string time = to_string_clipped( time_duration::from_turns( time_to_do ) );
3880 info.push_back( iteminfo( "DESCRIPTION",
3881 string_format( _( "It will be done in %s." ),
3882 time.c_str() ) ) );
3883 }
3884 }
3885 }
3886
3887 std::map<std::string, std::string>::const_iterator item_note = item_vars.find( "item_note" );
3888 std::map<std::string, std::string>::const_iterator item_note_tool =
3889 item_vars.find( "item_note_tool" );
3890
3891 if( item_note != item_vars.end() && parts->test( iteminfo_parts::DESCRIPTION_NOTES ) ) {
3893 std::string ntext;
3894 const inscribe_actor *use_actor = nullptr;
3895 if( item_note_tool != item_vars.end() ) {
3896 const use_function *use_func = itype_id( item_note_tool->second )->get_use( "inscribe" );
3897 use_actor = dynamic_cast<const inscribe_actor *>( use_func->get_actor_ptr() );
3898 }
3899 if( use_actor ) {
3900 //~ %1$s: gerund (e.g. carved), %2$s: item name, %3$s: inscription text
3901 ntext = string_format( pgettext( "carving", "%1$s on the %2$s is: %3$s" ),
3902 use_actor->gerund, tname(), item_note->second );
3903 } else {
3904 //~ %1$s: inscription text
3905 ntext = string_format( pgettext( "carving", "Note: %1$s" ), item_note->second );
3906 }
3907 info.push_back( iteminfo( "DESCRIPTION", ntext ) );
3908 }
3909
3910 if( this->get_var( "die_num_sides", 0 ) != 0 ) {
3911 info.emplace_back( "DESCRIPTION",
3912 string_format( _( "* This item can be used as a <info>die</info>, "
3913 "and has <info>%d</info> sides." ),
3914 static_cast<int>( this->get_var( "die_num_sides",
3915 0 ) ) ) );
3916 }
3917
3918 // Price and barter value
3919 const int price_preapoc = price( false ) * batch;
3920 const int price_postapoc = price( true ) * batch;
3921 if( parts->test( iteminfo_parts::BASE_PRICE ) ) {
3923 info.push_back( iteminfo( "BASE", _( "Price: " ), _( "$<num>" ),
3925 static_cast<double>( price_preapoc ) / 100 ) );
3926 }
3927 if( price_preapoc != price_postapoc && parts->test( iteminfo_parts::BASE_BARTER ) ) {
3928 info.push_back( iteminfo( "BASE", space + _( "Barter value: " ), _( "$<num>" ),
3930 static_cast<double>( price_postapoc ) / 100 ) );
3931 }
3932
3933 // Recipes using this item as an ingredient
3935 itype_id tid = contents.empty() ? typeId() : contents.front().typeId();
3936 const inventory &crafting_inv = you.crafting_inventory();
3937
3938 const recipe_subset available_recipe_subset = you.get_available_recipes( crafting_inv, nullptr,
3940 const std::set<const recipe *> &item_recipes = available_recipe_subset.of_component( tid );
3941
3942 if( item_recipes.empty() ) {
3944 info.push_back( iteminfo( "DESCRIPTION",
3945 _( "You know of nothing you could craft with it." ) ) );
3946 } else {
3947 if( item_recipes.size() > 24 ) {
3949 info.push_back( iteminfo( "DESCRIPTION",
3950 _( "You know dozens of things you could craft with it." ) ) );
3951 } else if( item_recipes.size() > 12 ) {
3953 info.push_back( iteminfo( "DESCRIPTION",
3954 _( "You could use it to craft various other things." ) ) );
3955 } else {
3956 // Extract item names from recipes and sort them
3957 std::vector<std::pair<std::string, bool>> result_names;
3959 item_recipes.begin(), item_recipes.end(),
3960 std::back_inserter( result_names ),
3961 [&crafting_inv]( const recipe * r ) {
3962 bool can_make = r->deduped_requirements().can_make_with_inventory(
3963 crafting_inv, r->get_component_filter() );
3964 return std::make_pair( r->result_name(), can_make );
3965 } );
3966 std::sort( result_names.begin(), result_names.end(), localized_compare );
3967 const std::string recipes =
3968 enumerate_as_string( result_names.begin(), result_names.end(),
3969 []( const std::pair<std::string, bool> &p ) {
3970 if( p.second ) {
3971 return p.first;
3972 } else {
3973 return string_format( "<dark>%s</dark>", p.first );
3974 }
3975 } );
3977 info.push_back( iteminfo( "DESCRIPTION",
3978 string_format( _( "You could use it to craft: %s" ),
3979 recipes ) ) );
3980 }
3981 }
3982 }
3983 if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
3984 const ascii_art_id art = type->picture_id;
3985 if( art.is_valid() ) {
3986 for( const std::string &line : art->picture ) {
3987 info.push_back( iteminfo( "DESCRIPTION", line ) );
3988 }
3989 }
3990 }
3991}
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:557
std::vector< std::string > picture
Definition: ascii_art.h:22
iterator begin() const
Definition: flat_set.h:83
iterator end() const
Definition: flat_set.h:86
This is a iuse_transform that uses the age of the item instead of a counter.
Definition: iuse_actor.h:289
int time_to_do(const item &it) const
How much longer (in turns) until the transformation can be done, can be negative.
Definition: iuse_actor.cpp:883
Writes on stuff (ground or items)
Definition: iuse_actor.h:610
translation gerund
Definition: iuse_actor.h:633
const FlagsSetType & get_flags() const
returs read-only set of flags of this item (not including flags from item type or gunmods)
Definition: item.cpp:5380
const std::vector< itype_id > & brewing_results() const
The results of fermenting this item.
Definition: item.cpp:5961
std::set< fault_id > faults
What faults (if any) currently apply to this item.
Definition: item.h:2174
time_duration brewing_time() const
Time for this item to be fully fermented.
Definition: item.cpp:5956
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6488
void bionic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3297
int price(bool practical) const
Returns the monetary value of an item.
Definition: item.cpp:4948
void armor_fit_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2762
Definition: flag.h:15
std::string info() const
Get informative text for display in UI.
Definition: flag.h:30
recipe_subset get_available_recipes(const inventory &crafting_inv, const std::vector< npc * > *helpers=nullptr, recipe_filter filter=nullptr) const
Returns all available recipes (from books and npc companions)
Definition: player.cpp:298
const std::set< const recipe * > & of_component(const itype_id &id) const
Returns all recipes which could use component.
static const std::string flag_RADIOSIGNAL_2("RADIOSIGNAL_2")
static const std::string flag_FIRE_TWOHAND("FIRE_TWOHAND")
static const std::string flag_RADIOSIGNAL_1("RADIOSIGNAL_1")
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
static const std::string flag_USE_UPS("USE_UPS")
static const std::string flag_RECHARGE("RECHARGE")
static const std::string flag_RADIO_ACTIVATION("RADIO_ACTIVATION")
static const std::string flag_RADIO_INVOKE_PROC("RADIO_INVOKE_PROC")
static const std::string flag_CONSUMABLE("CONSUMABLE")
static const std::string flag_NO_RELOAD("NO_RELOAD")
static const std::string flag_RADIOSIGNAL_3("RADIOSIGNAL_3")
static const std::string flag_LEAK_ALWAYS("LEAK_ALWAYS")
static const std::string flag_RADIO_MOD("RADIO_MOD")
std::unique_ptr< Item_factory > item_controller
@ DESCRIPTION_RECHARGE_UPSCAPABLE
@ DESCRIPTION_GUNMOD_DISABLESSIGHTS
@ DESCRIPTION_BREWABLE_DURATION
@ DESCRIPTION_RADIO_ACTIVATION_CHANNEL
@ DESCRIPTION_BREWABLE_PRODUCTS
@ DESCRIPTION_RECHARGE_NORELOAD
@ DESCRIPTION_ACTIVATABLE_TRANSFORMATION
@ DESCRIPTION_BIONIC_ARMOR_INTERFACE
@ DESCRIPTION_RADIOACTIVITY_DAMAGED
@ DESCRIPTION_RADIO_ACTIVATION_PROC
@ DESCRIPTION_RECHARGE_UPSMODDED
@ DESCRIPTION_GUNMOD_CONSUMABLE
@ DESCRIPTION_RADIOACTIVITY_ALWAYS
@ DESCRIPTION_RADIO_ACTIVATION
@ DESCRIPTION_APPLICABLE_RECIPES
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6290
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1556
recipe_filter recipe_filter_by_component(const itype_id &c)
ascii_art_id picture_id
Definition: itype.h:880
constexpr localized_comparator localized_compare
Definition: translations.h:342

References _, armor_fit_info(), BASE_BARTER, BASE_PRICE, BASE_RIGIDITY, cata::flat_set< T, Compare, Data >::begin(), bionic_info(), brewing_results(), brewing_time(), itype::can_use(), charges, conductive(), contents, Character::crafting_inventory(), damage(), debug, DESCRIPTION_ACTIVATABLE_TRANSFORMATION, DESCRIPTION_APPLICABLE_RECIPES, DESCRIPTION_BIONIC_ARMOR_INTERFACE, DESCRIPTION_BREWABLE_DURATION, DESCRIPTION_BREWABLE_PRODUCTS, DESCRIPTION_CONDUCTIVITY, DESCRIPTION_FAULTS, DESCRIPTION_FLAGS, DESCRIPTION_GUNMOD_CONSUMABLE, DESCRIPTION_GUNMOD_DISABLESSIGHTS, DESCRIPTION_HOLSTERS, DESCRIPTION_NOTES, DESCRIPTION_RADIO_ACTIVATION, DESCRIPTION_RADIO_ACTIVATION_CHANNEL, DESCRIPTION_RADIO_ACTIVATION_PROC, DESCRIPTION_RADIOACTIVITY_ALWAYS, DESCRIPTION_RADIOACTIVITY_DAMAGED, DESCRIPTION_RECHARGE_NORELOAD, DESCRIPTION_RECHARGE_UPSCAPABLE, DESCRIPTION_RECHARGE_UPSMODDED, DESCRIPTION_TWOHANDED, item_contents::empty(), cata::flat_set< T, Compare, Data >::end(), enumerate_as_string(), faults, flag_CONDUCTIVE(), flag_CONSUMABLE(), flag_DISABLE_SIGHTS(), flag_FIRE_TWOHAND(), flag_LEAK_ALWAYS(), flag_LEAK_DAM(), flag_NO_RELOAD(), flag_RADIO_ACTIVATION(), flag_RADIO_INVOKE_PROC(), flag_RADIO_MOD(), flag_RADIOACTIVE(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_RECHARGE(), flag_USE_UPS(), flag_USES_BIONIC_POWER(), time_duration::from_turns(), item_contents::front(), inscribe_actor::gerund, json_flag::get(), use_function::get_actor_ptr(), player::get_available_recipes(), get_avatar(), get_flags(), itype::get_flags(), itype::get_use(), get_var(), has_flag(), has_own_flag(), Character::has_trait(), json_flag::info(), info(), insert_separation_line(), is_armor(), is_brewable(), iteminfo::is_decimal, is_gun(), is_gunmod(), is_null(), is_power_armor(), is_tool(), item_controller, item_vars, itype_id, localized_compare, iteminfo::lower_is_better, made_of(), nname(), iteminfo::no_newline, recipe_subset::of_component(), pgettext(), price(), ptr(), recipe_filter_by_component(), itype::rigid, sign::space, string_format(), iteminfo_query::test(), time, delayed_transform_iuse::time_to_do(), tname(), to_string_clipped(), trait_WOOLALLERGY, iexamine::transform(), type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ find_armor_data()

const islot_armor * item::find_armor_data ( ) const

If this is an armor item, return its armor data.

You should probably not use this function, use the various functions above (like get_storage) to access armor data directly.

Definition at line 6692 of file item.cpp.

6693{
6694 if( type->armor ) {
6695 return &*type->armor;
6696 }
6697 // Currently the only way to make a non-armor item into armor is to install a gun mod.
6698 // The gunmods are stored in the items contents, as are the contents of a container, and the
6699 // tools in a tool belt (a container actually), or the ammo in a quiver (container again).
6700 for( const item *mod : gunmods() ) {
6701 if( mod->type->armor ) {
6702 return &*mod->type->armor;
6703 }
6704 }
6705 return nullptr;
6706}
cata::value_ptr< islot_armor > armor
Definition: itype.h:823

References itype::armor, gunmods(), and type.

Referenced by get_base_env_resist(), get_base_env_resist_w_filter(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_env_resist(), get_storage(), get_thickness(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), is_armor(), and is_sided().

◆ fire_resist()

int item::fire_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Definition at line 6171 of file item.cpp.

6172{
6173 if( to_self ) {
6174 // Fire damages items in a different way
6175 return INT_MAX;
6176 }
6177
6178 float resist = 0.0;
6180 if( is_null() ) {
6181 return 0.0;
6182 }
6183
6184 const std::vector<const material_type *> mat_types = made_of_types();
6185 if( !mat_types.empty() ) {
6186 for( const material_type *mat : mat_types ) {
6187 resist += mat->fire_resist();
6188 }
6189 // Average based on number of materials.
6190 resist /= mat_types.size();
6191 }
6192
6193 const int env = get_env_resist( base_env_resist );
6194 if( env < 10 ) {
6195 // Iron resists immersion in magma, iron-clad knight won't.
6196 resist *= env / 10.0f;
6197 }
6198
6199 return std::lround( resist + mod );
6200}
@ clothing_mod_type_fire
Definition: clothing_mod.h:18

References clothing_mod_type_fire, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ flammable()

bool item::flammable ( int  threshold = 0) const

Whether the items is flammable.

(Make sure to keep this in sync with fire code in fields.cpp)

Parameters
thresholdItem is flammable if it provides more fuel than threshold.

Definition at line 8322 of file item.cpp.

8323{
8324 const std::vector<const material_type *> &mats = made_of_types();
8325 if( mats.empty() ) {
8326 // Don't know how to burn down something made of nothing.
8327 return false;
8328 }
8329
8330 int flammability = 0;
8331 units::volume volume_per_turn = 0_ml;
8332 for( const material_type *m : mats ) {
8333 const mat_burn_data &bd = m->burn_data( 1 );
8334 if( bd.immune ) {
8335 // Made to protect from fire
8336 return false;
8337 }
8338
8339 flammability += bd.fuel;
8340 volume_per_turn += bd.volume_per_turn;
8341 }
8342
8343 if( threshold == 0 || flammability <= 0 ) {
8344 return flammability > 0;
8345 }
8346
8347 volume_per_turn /= mats.size();
8348 units::volume vol = base_volume();
8349 if( volume_per_turn > 0_ml && volume_per_turn < vol ) {
8350 flammability = flammability * volume_per_turn / vol;
8351 } else {
8352 // If it burns well, it provides a bonus here
8353 flammability *= vol / units::legacy_volume_factor;
8354 }
8355
8356 return flammability > threshold;
8357}
Contains burning parameters for a given material.
Definition: fire.h:46
bool immune
If this is true, an object will not burn or be destroyed by fire.
Definition: fire.h:48
units::volume volume_per_turn
If non-zero and lower than item's volume, scale burning by volume_penalty / volume.
Definition: fire.h:50
float fuel
Fuel contributed per tick when this material burns.
Definition: fire.h:52

References base_volume(), mat_burn_data::fuel, mat_burn_data::immune, units::legacy_volume_factor, made_of_types(), and mat_burn_data::volume_per_turn.

Referenced by Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), and monster::process_turn().

◆ food_info()

void item::food_info ( const item food_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug,
temperature_flag  temperature 
) const
Survival >=3 allows detection of poisonous food Survival >=5 allows detection of hallucinogenic food

Definition at line 1675 of file item.cpp.

1678{
1679 nutrients min_nutr;
1680 nutrients max_nutr;
1681 avatar &you = get_avatar();
1682
1683 std::string recipe_exemplar = get_var( "recipe_exemplar", "" );
1684 if( recipe_exemplar.empty() ) {
1685 min_nutr = max_nutr = you.compute_effective_nutrients( *food_item );
1686 } else {
1687 std::tie( min_nutr, max_nutr ) =
1688 you.compute_nutrient_range( *food_item, recipe_id( recipe_exemplar ) );
1689 }
1690
1691 bool show_nutr = parts->test( iteminfo_parts::FOOD_NUTRITION ) ||
1693 if( min_nutr != max_nutr && show_nutr ) {
1694 info.emplace_back(
1695 "FOOD", _( "Nutrition will <color_cyan>vary with chosen ingredients</color>." ) );
1696 if( recipe_dict.is_item_on_loop( food_item->typeId() ) ) {
1697 info.emplace_back(
1698 "FOOD", _( "Nutrition range cannot be calculated accurately due to "
1699 "<color_red>recipe loops</color>." ) );
1700 }
1701 }
1702
1703 const std::string space = " ";
1704 if( max_nutr.kcal != 0 || food_item->get_comestible()->quench != 0 ) {
1705 if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
1706 info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
1707 "", iteminfo::no_newline, min_nutr.kcal ) );
1708 if( max_nutr.kcal != min_nutr.kcal ) {
1709 info.push_back( iteminfo( "FOOD", _( "-" ),
1710 "", iteminfo::no_newline, max_nutr.kcal ) );
1711 }
1712 }
1713 if( parts->test( iteminfo_parts::FOOD_QUENCH ) ) {
1714 info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
1715 food_item->get_comestible()->quench ) );
1716 }
1717 }
1718
1719 const std::pair<int, int> fun_for_food_item = you.fun_for( *food_item );
1720 if( fun_for_food_item.first != 0 && parts->test( iteminfo_parts::FOOD_JOY ) ) {
1721 info.push_back( iteminfo( "FOOD", _( "Enjoyability: " ), fun_for_food_item.first ) );
1722 }
1723
1724 if( parts->test( iteminfo_parts::FOOD_PORTIONS ) ) {
1725 info.push_back( iteminfo( "FOOD", _( "Portions: " ),
1726 std::abs( static_cast<int>( food_item->charges ) * batch ) ) );
1727 }
1728 if( food_item->corpse != nullptr && parts->test( iteminfo_parts::FOOD_SMELL ) &&
1729 ( debug || ( g != nullptr && ( you.has_trait( trait_CARNIVORE ) ||
1731 info.push_back( iteminfo( "FOOD", _( "Smells like: " ) + food_item->corpse->nname() ) );
1732 }
1733
1734 auto format_vitamin = [&]( const std::pair<vitamin_id, int> &v, bool display_vitamins ) {
1735 const bool is_vitamin = v.first->type() == vitamin_type::VITAMIN;
1736 // only display vitamins that we actually require
1737 if( you.vitamin_rate( v.first ) == 0_turns || v.second == 0 ||
1738 display_vitamins != is_vitamin || v.first->has_flag( flag_NO_DISPLAY ) ) {
1739 return std::string();
1740 }
1741 const double multiplier = you.vitamin_rate( v.first ) / 1_days * 100;
1742 const int min_value = min_nutr.get_vitamin( v.first );
1743 const int max_value = v.second;
1744 const int min_rda = std::lround( min_value * multiplier );
1745 const int max_rda = std::lround( max_value * multiplier );
1746 const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
1747 return string_format( format, v.first->name(), min_value, max_value );
1748 };
1749
1750 const auto max_nutr_vitamins = sorted_lex( max_nutr.vitamins );
1751 const std::string required_vits = enumerate_as_string(
1752 max_nutr_vitamins.begin(),
1753 max_nutr_vitamins.end(),
1754 [&]( const std::pair<vitamin_id, int> &v ) {
1755 return format_vitamin( v, true );
1756 } );
1757
1758 const std::string effect_vits = enumerate_as_string(
1759 max_nutr_vitamins.begin(),
1760 max_nutr_vitamins.end(),
1761 [&]( const std::pair<vitamin_id, int> &v ) {
1762 return format_vitamin( v, false );
1763 } );
1764
1765 if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
1766 info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
1767 }
1768
1769 if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
1770 info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
1771 }
1772
1774
1775 if( you.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
1776 info.emplace_back( "DESCRIPTION",
1777 _( "* This food will cause an <bad>allergic reaction</bad>." ) );
1778 }
1779
1780 if( food_item->has_flag( flag_CANNIBALISM ) &&
1782 if( !you.has_trait_flag( trait_flag_CANNIBAL ) ) {
1783 info.emplace_back( "DESCRIPTION",
1784 _( "* This food contains <bad>human flesh</bad>." ) );
1785 } else {
1786 info.emplace_back( "DESCRIPTION",
1787 _( "* This food contains <good>human flesh</good>." ) );
1788 }
1789 }
1790
1791 if( food_item->is_tainted() && parts->test( iteminfo_parts::FOOD_CANNIBALISM ) ) {
1792 info.emplace_back( "DESCRIPTION",
1793 _( "* This food is <bad>tainted</bad> and will poison you." ) );
1794 }
1795
1796 ///\EFFECT_SURVIVAL >=3 allows detection of poisonous food
1797 if( food_item->has_flag( flag_HIDDEN_POISON ) && you.get_skill_level( skill_survival ) >= 3 &&
1798 parts->test( iteminfo_parts::FOOD_POISON ) ) {
1799 info.emplace_back( "DESCRIPTION",
1800 _( "* On closer inspection, this appears to be "
1801 "<bad>poisonous</bad>." ) );
1802 }
1803
1804 ///\EFFECT_SURVIVAL >=5 allows detection of hallucinogenic food
1805 if( food_item->has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 &&
1807 info.emplace_back( "DESCRIPTION",
1808 _( "* On closer inspection, this appears to be "
1809 "<neutral>hallucinogenic</neutral>." ) );
1810 }
1811
1812 if( food_item->goes_bad() && parts->test( iteminfo_parts::FOOD_ROT ) ) {
1813 const std::string rot_time = to_string_clipped( food_item->get_shelf_life() );
1814 info.emplace_back( "DESCRIPTION",
1815 string_format( _( "* This food is <neutral>perishable</neutral>, "
1816 "and at room temperature has an estimated nominal "
1817 "shelf life of <info>%s</info>." ), rot_time ) );
1818
1819
1820 if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
1821 const char *temperature_description;
1822 bool print_freshness_duration = false;
1823 // There should be a better way to do this...
1824 switch( temperature ) {
1827 temperature_description = _( "* Current storage conditions <bad>do not</bad> "
1828 "protect this item from rot." );
1829 }
1830 break;
1833 temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
1834 "protect this item from rot. It will stay fresh at least <info>%s</info>." );
1835 print_freshness_duration = true;
1836 }
1837 break;
1839 temperature_description = _( "* Current storage conditions <good>fully</good> "
1840 "protect this item from rot. It will stay fresh indefinitely." );
1841 }
1842 break;
1843 default: {
1844 temperature_description = "BUGGED TEMPERATURE INFO";
1845 }
1846 }
1847
1848 if( print_freshness_duration ) {
1849 time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
1850 std::string time_string = to_string_clipped( remaining_fresh );
1851 info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
1852 } else {
1853 info.emplace_back( "DESCRIPTION", temperature_description );
1854 }
1855 }
1856
1857 if( !food_item->rotten() ) {
1858 info.emplace_back( "DESCRIPTION", get_freshness_description( *food_item ) );
1859 }
1860
1861 if( food_item->has_flag( flag_NO_PARASITES ) ) {
1862 info.emplace_back( "DESCRIPTION",
1863 _( "* It seems that deep freezing <good>killed all "
1864 "parasites</good>." ) );
1865 }
1866 if( food_item->rotten() ) {
1867 if( you.has_bionic( bio_digestion ) ) {
1868 info.push_back( iteminfo( "DESCRIPTION",
1869 _( "This food has started to <neutral>rot</neutral>, "
1870 "but <info>your bionic digestion can tolerate "
1871 "it</info>." ) ) );
1872 } else if( you.has_trait( trait_SAPROVORE ) ) {
1873 info.push_back( iteminfo( "DESCRIPTION",
1874 _( "This food has started to <neutral>rot</neutral>, "
1875 "but <info>you can tolerate it</info>." ) ) );
1876 } else {
1877 info.push_back( iteminfo( "DESCRIPTION",
1878 _( "This food has started to <bad>rot</bad>. "
1879 "<info>Eating</info> it would be a <bad>very bad "
1880 "idea</bad>." ) ) );
1881 }
1882 }
1883 }
1884}
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:106
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3213
nutrients compute_effective_nutrients(const item &) const
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:849
time_duration minimum_freshness_duration(temperature_flag temperature) const
Time that this item is guaranteed to stay fresh.
Definition: item.cpp:5710
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:10131
bool is_tainted() const
Is item derived from a zombie?
Definition: item.cpp:9824
bool is_item_on_loop(const itype_id &) const
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_NO_DISPLAY("NO_DISPLAY")
static const bionic_id bio_digestion("bio_digestion")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const std::string flag_NO_PARASITES("NO_PARASITES")
static const std::string trait_flag_CANNIBAL("CANNIBAL")
static const skill_id skill_survival("survival")
static std::string get_freshness_description(const item &food_item)
Definition: item.cpp:1116
constexpr T max_value()
recipe_dictionary recipe_dict
int kcal
amount of kcal this food has
Definition: stomach.h:18
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21
int get_vitamin(const vitamin_id &) const
Definition: stomach.cpp:42
string_id< recipe > recipe_id
Definition: type_id.h:143
@ VITAMIN
Definition: vitamin.h:19

References _, AEP_SUPER_CLAIRVOYANCE, Character::allergy_type(), bio_digestion, charges, Character::compute_effective_nutrients(), Character::compute_nutrient_range(), corpse, debug, enumerate_as_string(), flag_CANNIBALISM(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_NO_DISPLAY(), flag_NO_PARASITES(), FOOD_CANNIBALISM, FOOD_HALLUCINOGENIC, FOOD_JOY, FOOD_NUTRITION, FOOD_POISON, FOOD_PORTIONS, FOOD_QUENCH, FOOD_ROT, FOOD_ROT_STORAGE, FOOD_SMELL, FOOD_VIT_EFFECTS, FOOD_VITAMINS, format(), Character::fun_for(), g, get_avatar(), get_comestible(), get_freshness_description(), get_shelf_life(), Character::get_skill_level(), get_var(), nutrients::get_vitamin(), goes_bad(), Character::has_artifact_with(), Character::has_bionic(), has_flag(), Character::has_trait(), Character::has_trait_flag(), info(), insert_separation_line(), recipe_dictionary::is_item_on_loop(), is_tainted(), nutrients::kcal, detail::max_value(), minimum_freshness_duration(), mtype::nname(), iteminfo::no_newline, recipe_dict, rotten(), skill_survival, sorted_lex(), sign::space, string_format(), TEMP_FREEZER, TEMP_FRIDGE, TEMP_HEATER, TEMP_NORMAL, TEMP_ROOT_CELLAR, iteminfo_query::test(), to_string_clipped(), trait_CARNIVORE, trait_flag_CANNIBAL(), trait_SAPROVORE, typeId(), VITAMIN, Character::vitamin_rate(), and nutrients::vitamins.

Referenced by info().

◆ fuel_energy()

float item::fuel_energy ( ) const

Returns energy of one charge of this item as fuel for an engine.

Definition at line 6826 of file item.cpp.

6827{
6828 return is_fuel() ? type->fuel->energy : 0.0f;
6829}
bool is_fuel() const
Definition: item.cpp:6770
cata::value_ptr< islot_fuel > fuel
Definition: itype.h:829

References itype::fuel, is_fuel(), and type.

Referenced by Character::burn_fuel(), vehicle_part::consume_energy(), vehicle::consume_fuel(), vehicle::consumption_per_hour(), Character::get_acquirable_energy(), game::on_move_effects(), and Character::passive_power_gen().

◆ fuel_pump_terrain()

std::string item::fuel_pump_terrain ( ) const

Returns the string of the id of the terrain that pumps this fuel, if any.

Definition at line 6831 of file item.cpp.

6832{
6833 return is_fuel() ? type->fuel->pump_terrain : "t_null";
6834}

References itype::fuel, is_fuel(), and type.

Referenced by map::place_gas_pump().

◆ get_available_recipes()

std::vector< std::pair< const recipe *, int > > item::get_available_recipes ( const player u) const

Enumerates recipes available from this book and the skill level required to use them.

Definition at line 7125 of file item.cpp.

7126{
7127 std::vector<std::pair<const recipe *, int>> recipe_entries;
7128 if( is_book() ) {
7129 for( const islot_book::recipe_with_description_t &elem : type->book->recipes ) {
7130 if( u.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level ) {
7131 recipe_entries.push_back( std::make_pair( elem.recipe, elem.skill_level ) );
7132 }
7133 }
7134 } else if( has_var( "EIPC_RECIPES" ) ) {
7135 // See einkpc_download_memory_card() in iuse.cpp where this is set.
7136 const std::string recipes = get_var( "EIPC_RECIPES" );
7137 // Capture the index one past the delimiter, i.e. start of target string.
7138 size_t first_string_index = recipes.find_first_of( ',' ) + 1;
7139 while( first_string_index != std::string::npos ) {
7140 size_t next_string_index = recipes.find_first_of( ',', first_string_index );
7141 if( next_string_index == std::string::npos ) {
7142 break;
7143 }
7144 std::string new_recipe = recipes.substr( first_string_index,
7145 next_string_index - first_string_index );
7146 const recipe *r = &recipe_id( new_recipe ).obj();
7147 if( u.get_skill_level( r->skill_used ) >= r->difficulty ) {
7148 recipe_entries.push_back( std::make_pair( r, r->difficulty ) );
7149 }
7150 first_string_index = next_string_index + 1;
7151 }
7152 }
7153 return recipe_entries;
7154}
int difficulty
Definition: recipe.h:62

References itype::book, recipe::difficulty, Character::get_skill_level(), get_var(), has_var(), is_book(), string_id< T >::obj(), islot_book::recipe_with_description_t::recipe, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, and type.

Referenced by avatar::do_read(), and player::get_recipes_from_books().

◆ get_base_env_resist_w_filter()

int item::get_base_env_resist_w_filter ( ) const

Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed.

Used in iuse::gasmask to change protection of a gas mask if it has (or don't has) filters. For other applications use get_env_resist() above.

Definition at line 5787 of file item.cpp.

5788{
5789 const islot_armor *t = find_armor_data();
5790 if( t == nullptr ) {
5791 return is_pet_armor() ? type->pet_armor->env_resist_w_filter : 0;
5792 }
5793 return t->env_resist_w_filter;
5794}
const islot_armor * find_armor_data() const
If this is an armor item, return its armor data.
Definition: item.cpp:6692
int env_resist_w_filter
Environmental protection of a gas mask with installed filter.
Definition: itype.h:268
cata::value_ptr< islot_pet_armor > pet_armor
Definition: itype.h:824

References islot_armor::env_resist_w_filter, find_armor_data(), is_pet_armor(), itype::pet_armor, and type.

Referenced by armor_protection_info(), iuse::dive_tank(), and iuse::gasmask().

◆ get_base_material()

const material_type & item::get_base_material ( ) const

Get the basic (main) material of this item.

May return the null-material.

Definition at line 7161 of file item.cpp.

7162{
7163 const std::vector<material_id> &mats = made_of();
7164 return mats.empty() ? material_id::NULL_ID().obj() : mats.front().obj();
7165}

References made_of(), string_id< material_type >::NULL_ID(), and string_id< T >::obj().

Referenced by Character::armor_absorb(), and durability_indicator().

◆ get_cable_target()

std::optional< tripoint > item::get_cable_target ( Character p,
const tripoint pos 
) const

Gets the point (vehicle tile) the cable is connected to.

Returns nothing if not connected to anything.

Definition at line 9349 of file item.cpp.

9350{
9351 const std::string &state = get_var( "state" );
9352 if( state != "pay_out_cable" && state != "cable_charger_link" ) {
9353 return std::nullopt;
9354 }
9355 map &here = get_map();
9356 const optional_vpart_position vp_pos = here.veh_at( pos );
9357 if( vp_pos ) {
9358 const std::optional<vpart_reference> seat = vp_pos.part_with_feature( "BOARDABLE", true );
9359 if( seat && p == seat->vehicle().get_passenger( seat->part_index() ) ) {
9360 return pos;
9361 }
9362 }
9363
9364 tripoint source( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) );
9365
9366 return here.getlocal( source );
9367}
Manage and cache data about a part of the map.
Definition: map.h:384
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2483
auto here(const Character &you) -> elevator::tiles

References get_map(), get_var(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), and optional_vpart_position::part_with_feature().

Referenced by process_cable().

◆ get_cached_tool_selections()

const std::vector< comp_selection< tool_comp > > & item::get_cached_tool_selections ( ) const

Definition at line 10125 of file item.cpp.

10126{
10127 assert( craft_data_ );
10128 return craft_data_->cached_tool_selections;
10129}

References craft_data_.

◆ get_category()

const item_category & item::get_category ( ) const

Definition at line 8692 of file item.cpp.

8693{
8694 if( is_container() && !contents.empty() ) {
8695 return contents.front().get_category();
8696 }
8697
8698 static item_category null_category;
8699 return type->category_force.is_valid() ? type->category_force.obj() : null_category;
8700}
Contains metadata for one category of items.
Definition: item_category.h:35
item_category_id category_force
If set via JSON forces item category to this (preventing automatic assignment)
Definition: itype.h:974

References itype::category_force, contents, item_contents::empty(), item_contents::front(), get_category(), is_container(), string_id< T >::is_valid(), string_id< T >::obj(), and type.

Referenced by inventory_selector::add_items(), basic_info(), json_talk_topic::gen_responses(), get_category(), inventory_entry::get_category_ptr(), zone_manager::get_near_zone_type_for_item(), is_map(), map_item_stack::map_item_stack_sort(), operator<(), conditional_t< T >::set_has_item_category(), and spoilage_sort_order().

◆ get_chapters()

int item::get_chapters ( ) const

How many chapters the book has (if any).

Will be 0 if the item is not a book, or if it has no chapters at all. Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.

Definition at line 7099 of file item.cpp.

7100{
7101 if( !type->book ) {
7102 return 0;
7103 }
7104 return type->book->chapters;
7105}

References itype::book, and type.

Referenced by display_name(), character_funcs::get_book_fun_for(), get_remaining_chapters(), and io().

◆ get_clothing_mod_val()

float item::get_clothing_mod_val ( clothing_mod_type  type) const

Definition at line 10167 of file item.cpp.

10168{
10169 return get_var( get_clothing_mod_val_key( type ), 0.0f );
10170}
const std::string & get_clothing_mod_val_key(clothing_mod_type type)
Definition: item.cpp:10152

References anonymous_namespace{item.cpp}::get_clothing_mod_val_key(), get_var(), and type.

Referenced by acid_resist(), bash_resist(), bullet_resist(), cut_resist(), fire_resist(), get_encumber_when_containing(), get_storage(), and get_warmth().

◆ get_comestible()

◆ get_comestible_fun()

int item::get_comestible_fun ( ) const

Definition at line 5509 of file item.cpp.

5510{
5511 if( !is_comestible() ) {
5512 return 0;
5513 }
5514 int fun = get_comestible()->fun;
5515 for( const std::string &flag : item_tags ) {
5516 fun += json_flag::get( flag ).taste_mod();
5517 }
5518 for( const std::string &flag : type->get_flags() ) {
5519 fun += json_flag::get( flag ).taste_mod();
5520 }
5521
5522 return fun;
5523}
bool is_comestible() const
Definition: item.cpp:6597
int taste_mod() const
The flag's modifier on the fun value of comestibles.
Definition: flag.h:55

References json_flag::get(), get_comestible(), itype::get_flags(), is_comestible(), item_tags, json_flag::taste_mod(), and type.

Referenced by iuse::blech(), basecamp::distribute_food(), mattack::eat_food(), Character::fun_for(), med_info(), rate_food(), and npc::will_accept_from_player().

◆ get_contained()

const item & item::get_contained ( ) const

Return a contained item (if any and only one).

Definition at line 7061 of file item.cpp.

7062{
7063 if( contents.empty() ) {
7064 return null_item_reference();
7065 }
7066 return contents.front();
7067}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:327

References contents, item_contents::empty(), item_contents::front(), and null_item_reference().

Referenced by Character::consume_effects(), basecamp::distribute_food(), trading_window::get_var_trade(), Character::invoke_item(), examine_item_menu::rate_action_use(), ranged::throw_item(), try_consume(), avatar_funcs::use_item(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and npc::will_accept_from_player().

◆ get_container_capacity()

units::volume item::get_container_capacity ( ) const

It returns the total capacity (volume) of the container for liquids.

Definition at line 8402 of file item.cpp.

8403{
8404 if( !is_container() ) {
8405 return 0_ml;
8406 }
8407 return type->container->contains;
8408}

References itype::container, is_container(), and type.

Referenced by vehicle_part::ammo_capacity(), display_name(), get_remaining_capacity_for_liquid(), get_total_capacity(), is_funnel_container(), Item_factory::migrate_item(), Item_modifier::modify(), and ranged::throw_item().

◆ get_continue_reqs()

requirement_data item::get_continue_reqs ( ) const

Returns requirement data representing what is needed to resume work on an in progress craft.

Causes a debugmsg and returns empty requirement data if called on a non-craft

Returns
what is needed to continue craft, may be empty requirement data

Definition at line 976 of file crafting.cpp.

977{
978 if( !is_craft() ) {
979 debugmsg( "get_continue_reqs() called on non-craft '%s.' Aborting.", tname() );
980 return requirement_data();
981 }
983}
static requirement_data continue_requirements(const std::vector< item_comp > &required_comps, const std::list< item > &remaining_comps)
Returns the item requirements to continue an in progress craft with the passed components.

References components, requirement_data::continue_requirements(), craft_data_, debugmsg, is_craft(), and tname().

◆ get_corpse_name()

std::string item::get_corpse_name ( )

Returns name of deceased being if it had any or empty string if not.

Definition at line 9921 of file item.cpp.

9922{
9923 if( corpse_name.empty() ) {
9924 return std::string();
9925 }
9926 return corpse_name;
9927}
std::string corpse_name
Definition: item.h:2183

References corpse_name.

◆ get_coverage()

int item::get_coverage ( ) const

Returns the relative coverage that this item has when worn.

Values range from 0 (not covering anything, or no armor at all) to 100 (covering the whole body part). Items that cover more are more likely to absorb damage from attacks.

Definition at line 5910 of file item.cpp.

5911{
5912 const islot_armor *t = find_armor_data();
5913 if( t == nullptr ) {
5914 return 0;
5915 }
5916 return t->coverage;
5917}
int coverage
Percentage of the body part area that this item covers.
Definition: itype.h:256

References islot_armor::coverage, and find_armor_data().

Referenced by Character::armor_absorb(), armor_info(), armor_inventory_preset::armor_inventory_preset(), Character::block_ranged_hit(), relic_funcs::check_recharge_reqs(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), clothing_mod::get_mod_val(), character_funcs::is_bp_immune_to(), map::player_in_field(), tutorial_game::post_action(), wind_resistance_from_item_list(), and mdefense::zapback().

◆ get_covered_body_parts() [1/2]

body_part_set item::get_covered_body_parts ( ) const

Bitset of all covered body parts.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Definition at line 758 of file item.cpp.

759{
761}

References get_covered_body_parts(), and get_side().

Referenced by npc::adjust_worn(), Character::armor_absorb(), armor_info(), Character::can_swap(), Character::can_wear(), covers(), get_covered_body_parts(), layer_item(), on_wear(), player_morale::on_worn_item_washed(), player_morale::set_worn(), and weather_effect::wet_player().

◆ get_covered_body_parts() [2/2]

body_part_set item::get_covered_body_parts ( side  s) const

Bitset of all covered body parts, from a specific side.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Parameters
sSpecifies the side. Will be ignored for non-sided items.

Definition at line 763 of file item.cpp.

764{
765 body_part_set res;
766
767 if( is_gun() ) {
768 // Currently only used for guns with the should strap mod, other guns might
769 // go on another bodypart.
770 res.set( bp_torso );
771 }
772
773 const islot_armor *armor = find_armor_data();
774 if( armor == nullptr ) {
775 return res;
776 }
777
778 res |= armor->covers;
779
780 if( !armor->sided ) {
781 return res; // Just ignore the side.
782 }
783
784 switch( s ) {
785 case side::BOTH:
786 case side::num_sides:
787 break;
788
789 case side::LEFT:
790 res.reset( bp_arm_r );
791 res.reset( bp_hand_r );
792 res.reset( bp_leg_r );
793 res.reset( bp_foot_r );
794 break;
795
796 case side::RIGHT:
797 res.reset( bp_arm_l );
798 res.reset( bp_hand_l );
799 res.reset( bp_leg_l );
800 res.reset( bp_foot_l );
801 break;
802 }
803
804 return res;
805}
void set(const body_part &bp)
Definition: bodypart.h:256
void reset()
Definition: bodypart.h:259
bool sided
Whether this item can be worn on either side of the body.
Definition: itype.h:243
body_part_set covers
Bitfield of enum body_part TODO: document me.
Definition: itype.h:239

References BOTH, bp_arm_l, bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, islot_armor::covers, find_armor_data(), is_gun(), LEFT, num_sides, body_part_set::reset(), RIGHT, body_part_set::set(), and islot_armor::sided.

◆ get_enchantments()

const std::vector< enchantment > & item::get_enchantments ( ) const

Definition at line 6988 of file item.cpp.

6989{
6990 if( !is_relic() ) {
6991 static const std::vector<enchantment> fallback;
6992 return fallback;
6993 }
6994 return relic_data->get_enchantments();
6995}
bool is_relic() const
Definition: item.cpp:6983

References is_relic(), and relic_data.

Referenced by bonus_from_enchantments(), bonus_from_enchantments_wielded(), process_relic(), and Character::recalculate_enchantment_cache().

◆ get_encumber()

int item::get_encumber ( const Character p) const

Returns the encumbrance value that this item has when worn by given player.

Returns 0 if this is can not be worn at all.

Definition at line 5802 of file item.cpp.

5803{
5804
5805 units::volume contents_volume( 0_ml );
5806
5807 contents_volume += contents.item_size_modifier();
5808
5809 if( p.is_worn( *this ) ) {
5810 const islot_armor *t = find_armor_data();
5811
5812 if( t != nullptr && t->max_encumber != 0 ) {
5813 units::volume char_storage( 0_ml );
5814
5815 for( const item &e : p.worn ) {
5816 char_storage += e.get_storage();
5817 }
5818
5819 if( char_storage != 0_ml ) {
5820 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5821 contents_volume += units::from_milliliter( static_cast<int64_t>( t->storage.value() ) *
5822 p.inv.volume().value() / char_storage.value() );
5823 }
5824 }
5825 }
5826
5827 return get_encumber_when_containing( p, contents_volume );
5828}
inventory inv
Definition: character.h:1579
std::list< item > worn
Definition: character.h:1567
bool is_worn(const item &thing) const
Definition: character.h:1097
units::volume volume() const
Definition: inventory.cpp:1061
units::volume item_size_modifier() const
constexpr quantity< value_type, volume_in_milliliter_tag > from_milliliter(const value_type v)
Definition: units_volume.h:25
int max_encumber
When storage is full, how much it encumbers the player.
Definition: itype.h:251
units::volume storage
How much storage this items provides when worn.
Definition: itype.h:276

References contents, find_armor_data(), units::from_milliliter(), get_encumber_when_containing(), get_storage(), Character::inv, Character::is_worn(), item_contents::item_size_modifier(), islot_armor::max_encumber, islot_armor::storage, units::quantity< V, U >::value(), inventory::volume(), and Character::worn.

Referenced by armor_fit_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), repair_item_actor::can_repair_target(), Character::can_wear(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), repair_item_actor::default_action(), Character::head_cloth_encumbrance(), Character::item_wear_cost(), layer_item(), tname(), and sew_advanced_actor::use().

◆ get_encumber_when_containing()

int item::get_encumber_when_containing ( const Character p,
const units::volume contents_volume 
) const

Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents.

Returns 0 if this can not be worn at all.

Definition at line 5830 of file item.cpp.

5832{
5833 const islot_armor *t = find_armor_data();
5834 if( t == nullptr ) {
5835 // handle wearable guns (e.g. shoulder strap) as special case
5836 return is_gun() ? volume() / 750_ml : 0;
5837 }
5838 int encumber = t->encumber;
5839
5840 // Non-rigid items add additional encumbrance proportional to their volume
5841 if( !type->rigid ) {
5842 const int capacity = get_total_capacity().value();
5843
5844 if( t->max_encumber != 0 ) {
5845
5846 if( capacity > 0 ) {
5847 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5848 encumber += static_cast<int64_t>( t->max_encumber - t->encumber ) * contents_volume.value() /
5849 capacity;
5850 } else {
5851 debugmsg( "Non-rigid item (%s) without storage capacity.", tname() );
5852 }
5853 } else {
5854 encumber += contents_volume / 500_ml;
5855 }
5856 }
5857
5858 // Fit checked before changes, fitting shouldn't reduce penalties from patching.
5859 if( has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
5860 encumber = std::max( encumber / 2, encumber - 10 );
5861 }
5862
5863 // TODO: Should probably have sizing affect coverage
5864 const sizing sizing_level = get_sizing( p, encumber != 0 );
5865 switch( sizing_level ) {
5868 // non small characters have a HARD time wearing undersized clothing
5869 encumber *= 3;
5870 break;
5873 // clothes bag up around smol characters and encumber them more
5874 encumber *= 2;
5875 break;
5876 default:
5877 break;
5878 }
5879
5880 encumber += static_cast<int>( std::ceil( get_clothing_mod_val( clothing_mod_type_encumbrance ) ) );
5881
5882 return encumber;
5883}
@ clothing_mod_type_encumbrance
Definition: clothing_mod.h:22
int encumber
How much this item encumbers the player.
Definition: itype.h:247

References big_sized_small_char, clothing_mod_type_encumbrance, debugmsg, islot_armor::encumber, find_armor_data(), flag_FIT(), flag_VARSIZE(), get_clothing_mod_val(), get_sizing(), get_total_capacity(), has_flag(), human_sized_small_char, is_gun(), islot_armor::max_encumber, itype::rigid, small_sized_big_char, small_sized_human_char, tname(), type, units::quantity< V, U >::value(), and volume().

Referenced by armor_info(), and get_encumber().

◆ get_env_resist()

int item::get_env_resist ( int  override_base_resist = 0) const

Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn.

See player::get_env_resist. Higher values are better. For non-armor it returns 0.

Parameters
override_base_resistPass this to artifically increase the base resistance, so that the function can take care of other modifications to resistance for you. Note that this parameter will never decrease base resistnace.

Definition at line 5773 of file item.cpp.

5774{
5775 const islot_armor *t = find_armor_data();
5776 if( t == nullptr ) {
5777 return is_pet_armor() ? type->pet_armor->env_resist : 0;
5778 }
5779 // modify if item is a gas mask and has filter
5780 int resist_base = t->env_resist;
5781 int resist_filter = get_var( "overwrite_env_resist", 0 );
5782 int resist = std::max( { resist_base, resist_filter, override_base_resist } );
5783
5784 return std::lround( resist * get_relative_health() );
5785}
float get_relative_health() const
Relative item health.
Definition: item.cpp:6231
int env_resist
Resistance to environmental effects.
Definition: itype.h:264

References islot_armor::env_resist, find_armor_data(), get_relative_health(), get_var(), is_pet_armor(), itype::pet_armor, and type.

Referenced by acid_resist(), armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), fire_resist(), and tutorial_game::post_action().

◆ get_explosion_data()

struct fuel_explosion item::get_explosion_data ( )

Definition at line 6841 of file item.cpp.

6842{
6843 static struct fuel_explosion null_data;
6844 return has_explosion_data() ? type->fuel->explosion_data : null_data;
6845}
bool has_explosion_data() const
Definition: item.cpp:6836

References type.

Referenced by vehicle::explode_fuel().

◆ get_flags()

const item::FlagsSetType & item::get_flags ( ) const

returs read-only set of flags of this item (not including flags from item type or gunmods)

Definition at line 5380 of file item.cpp.

5381{
5382 return item_tags;
5383}

References item_tags.

Referenced by final_info().

◆ get_food() [1/2]

item * item::get_food ( )

Definition at line 6652 of file item.cpp.

6653{
6654 return get_food_impl( this );
6655}
static Item * get_food_impl(Item *it)
Definition: item.cpp:6641

References get_food_impl().

Referenced by basic_info(), color_in_inventory(), npc::consume_food(), npc::decide_needs(), zone_manager::get_near_zone_type_for_item(), and info().

◆ get_food() [2/2]

const item * item::get_food ( ) const

Definition at line 6657 of file item.cpp.

6658{
6659 return get_food_impl( this );
6660}

References get_food_impl().

◆ get_free_mod_locations()

int item::get_free_mod_locations ( const gunmod_location location) const

Number of mods that can still be installed into the given mod location, for non-guns it always returns 0.

Definition at line 4117 of file item.cpp.

4118{
4119 if( !is_gun() ) {
4120 return 0;
4121 }
4122
4123 std::map<gunmod_location, int> mod_locations = get_mod_locations();
4124
4125 const auto loc = mod_locations.find( location );
4126 if( loc == mod_locations.end() ) {
4127 return 0;
4128 }
4129 int result = loc->second;
4130 for( const item *elem : contents.all_items_top() ) {
4131 const cata::value_ptr<islot_gunmod> &mod = elem->type->gunmod;
4132 if( mod && mod->location == location ) {
4133 result--;
4134 }
4135 }
4136 return result;
4137}
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
std::map< gunmod_location, int > get_mod_locations() const
Get mod locations, including those added by other mods.
Definition: item.cpp:4100

References item_contents::all_items_top(), contents, get_mod_locations(), and is_gun().

Referenced by saw_stock_actor::can_use_on(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_gun_ups_drain()

int item::get_gun_ups_drain ( ) const

Definition at line 9939 of file item.cpp.

9940{
9941 int draincount = 0;
9942 if( type->gun ) {
9943 int modifier = 0;
9944 float multiplier = 1.0f;
9945 for( const item *mod : gunmods() ) {
9946 modifier += mod->type->gunmod->ups_charges_modifier;
9947 multiplier *= mod->type->gunmod->ups_charges_multiplier;
9948 }
9949 draincount = ( type->gun->ups_charges * multiplier ) + modifier;
9950 }
9951 return draincount;
9952}

References itype::gun, gunmods(), and type.

Referenced by character_funcs::ammo_count_for(), npc::decide_needs(), ranged::fire_gun(), ranged::gunmode_checks_weapon(), turret_data::query(), item_funcs::shots_remaining(), and target_ui::update_ammo_range_from_gun_mode().

◆ get_layer()

layer_level item::get_layer ( ) const

Returns clothing layer for item.

Definition at line 5885 of file item.cpp.

5886{
5887 if( type->armor ) {
5888 // We assume that an item will never have per-item flags defining its
5889 // layer, so we can defer to the itype.
5890 return type->layer;
5891 }
5892
5893 if( has_flag( flag_PERSONAL ) ) {
5894 return PERSONAL_LAYER;
5895 } else if( has_flag( flag_SKINTIGHT ) ) {
5896 return UNDERWEAR_LAYER;
5897 } else if( has_flag( flag_WAIST ) ) {
5898 return WAIST_LAYER;
5899 } else if( has_flag( flag_OUTER ) ) {
5900 return OUTER_LAYER;
5901 } else if( has_flag( flag_BELTED ) ) {
5902 return BELTED_LAYER;
5903 } else if( has_flag( flag_AURA ) ) {
5904 return AURA_LAYER;
5905 } else {
5906 return REGULAR_LAYER;
5907 }
5908}
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ PERSONAL_LAYER
Definition: enums.h:216
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224
layer_level layer
Definition: itype.h:999

References itype::armor, AURA_LAYER, BELTED_LAYER, flag_AURA(), flag_BELTED(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_WAIST(), has_flag(), itype::layer, OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, type, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by Character::item_wear_cost(), profession::items(), and layer_item().

◆ get_making()

const recipe & item::get_making ( ) const

Get the stored recipe for in progress crafts.

Causes a debugmsg if called on a non-craft and returns the null recipe.

Returns
the recipe in progress

Definition at line 10096 of file item.cpp.

10097{
10098 if( !craft_data_ ) {
10099 debugmsg( "'%s' is not a craft or has a null recipe", tname() );
10100 static const recipe dummy{};
10101 return dummy;
10102 }
10103 assert( craft_data_->making );
10104 return *craft_data_->making;
10105}

References craft_data_, debugmsg, and tname().

Referenced by iuse::craft(), handle_craft_failure(), and set_next_failure_point().

◆ get_min_str()

int item::get_min_str ( ) const

Definition at line 10051 of file item.cpp.

10052{
10053 if( type->gun ) {
10054 int min_str = type->min_str;
10055 for( const item *mod : gunmods() ) {
10056 min_str += mod->type->gunmod->min_str_required_mod;
10057 }
10058 return min_str > 0 ? min_str : 0;
10059 } else {
10060 return type->min_str;
10061 }
10062}
int min_str
Definition: itype.h:908

References itype::gun, gunmods(), itype::min_str, and type.

Referenced by basic_info(), Character::enumerate_unmet_requirements(), ranged::get_str_draw_penalty(), aim_activity_actor::load_RAS_weapon(), Character::meets_stat_requirements(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), and ranged::str_draw_range_modifier().

◆ get_mod_locations()

std::map< gunmod_location, int > item::get_mod_locations ( ) const

Get mod locations, including those added by other mods.

Definition at line 4100 of file item.cpp.

4101{
4102 std::map<gunmod_location, int> mod_locations = type->gun->valid_mod_locations;
4103
4104 for( const item *mod : gunmods() ) {
4105 if( !mod->type->gunmod->add_mod.empty() ) {
4106 std::map<gunmod_location, int> add_locations = mod->type->gunmod->add_mod;
4107
4108 for( const std::pair<const gunmod_location, int> &add_location : add_locations ) {
4109 mod_locations[add_location.first] += add_location.second;
4110 }
4111 }
4112 }
4113
4114 return mod_locations;
4115}

References itype::gun, gunmods(), and type.

Referenced by get_free_mod_locations(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_mtype()

const mtype * item::get_mtype ( ) const
Returns
The monster type associated with this item (corpse). It is usually the type that this item is made of (e.g. corpse, meat or blood of the monster). May return a null-pointer.

Definition at line 6635 of file item.cpp.

6636{
6637 return corpse;
6638}

References corpse.

Referenced by computer_session::action_blood_anal(), burn(), activity_handlers::butcher_finish(), butcher_time_to_cut(), butchery_drops_harvest(), butchery_quarter(), consider_butchery(), editmap::draw_main_ui_overlay(), and game::revive_corpse().

◆ get_next_failure_point()

int item::get_next_failure_point ( ) const

Get the failure point stored in this item.

returns INT_MAX if the failure point is unset. Causes a debugmsg and returns INT_MAX if called on a non-craft.

Returns
an integer >= 0 representing a percent to 5 decimal places. 67.32 percent would be represented as 6732000

Definition at line 896 of file crafting.cpp.

897{
898 if( !is_craft() ) {
899 debugmsg( "get_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
900 return INT_MAX;
901 }
902 return craft_data_->next_failure_point >= 0 ? craft_data_->next_failure_point : INT_MAX;
903}

References craft_data_, debugmsg, is_craft(), and tname().

◆ get_old_owner()

faction_id item::get_old_owner ( ) const

Definition at line 1290 of file item.cpp.

1291{
1293 return old_owner;
1294}
faction_id old_owner
Definition: item.h:2241
void validate_ownership() const
Definition: item.cpp:1296

References old_owner, and validate_ownership().

Referenced by is_old_owner().

◆ get_owner()

faction_id item::get_owner ( ) const

Definition at line 1284 of file item.cpp.

1285{
1287 return owner;
1288}

References owner, and validate_ownership().

Referenced by get_owner_name(), handle_pickup_ownership(), is_owned_by(), and query_consume_ownership().

◆ get_owner_name()

std::string item::get_owner_name ( ) const

Definition at line 1266 of file item.cpp.

1267{
1268 if( !g->faction_manager_ptr->get( get_owner() ) ) {
1269 debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
1270 return "no owner";
1271 }
1272 return g->faction_manager_ptr->get( get_owner() )->name;
1273}
faction_id get_owner() const
Definition: item.cpp:1284

References debugmsg, g, get_owner(), and tname().

Referenced by basic_info().

◆ get_pet_armor_bodytype()

std::string item::get_pet_armor_bodytype ( ) const

Definition at line 5951 of file item.cpp.

5952{
5953 return is_pet_armor() ? type->pet_armor->bodytype : "";
5954}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_max_vol()

units::volume item::get_pet_armor_max_vol ( ) const

Definition at line 5941 of file item.cpp.

5942{
5943 return is_pet_armor() ? type->pet_armor->max_vol : 0_ml;
5944}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_min_vol()

units::volume item::get_pet_armor_min_vol ( ) const

Definition at line 5946 of file item.cpp.

5947{
5948 return is_pet_armor() ? type->pet_armor->min_vol : 0_ml;
5949}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_plant_epoch()

time_duration item::get_plant_epoch ( ) const

Time it takes to grow from one stage to another.

There are 4 plant stages: seed, seedling, mature and harvest. Non-seed items return 0.

Definition at line 9786 of file item.cpp.

9787{
9788 if( !type->seed ) {
9789 return 0_turns;
9790 }
9791 // Growing times have been based around real world season length rather than
9792 // the default in-game season length to give
9793 // more accuracy for longer season lengths
9794 // Also note that seed->grow is the time it takes from seeding to harvest, this is
9795 // divided by 3 to get the time it takes from one plant state to the next.
9796 // TODO: move this into the islot_seed
9797 return type->seed->grow * calendar::season_ratio() / 3;
9798}
float season_ratio()
Definition: calendar.cpp:485
cata::value_ptr< islot_seed > seed
Definition: itype.h:836

References calendar::season_ratio(), itype::seed, and type.

◆ get_plant_name()

std::string item::get_plant_name ( ) const

The name of the plant as it appears in the various informational menus.

This should be translated. Returns an empty string for non-seed items.

Definition at line 9800 of file item.cpp.

9801{
9802 if( !type->seed ) {
9803 return std::string{};
9804 }
9805 return type->seed->plant_name.translated();
9806}

References itype::seed, and type.

Referenced by map::rotten_item_spawn().

◆ get_property_int64_t()

int64_t item::get_property_int64_t ( const std::string &  prop,
int64_t  def = 0 
) const

Definition at line 5396 of file item.cpp.

5397{
5398 const auto it = type->properties.find( prop );
5399 if( it != type->properties.end() ) {
5400 char *e = nullptr;
5401 int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
5402 if( !it->second.empty() && *e == '\0' ) {
5403 return r;
5404 }
5405 debugmsg( "invalid property '%s' for item '%s'", prop.c_str(), tname() );
5406 }
5407 return def;
5408}
std::map< std::string, std::string > properties
Definition: itype.h:886

References debugmsg, itype::properties, tname(), and type.

Referenced by ranged::throw_item().

◆ get_property_string()

std::string item::get_property_string ( const std::string &  prop,
const std::string &  def = "" 
) const

Get typed property for item.

Return same type as the passed default value, or string where no default provided

Definition at line 5390 of file item.cpp.

5391{
5392 const auto it = type->properties.find( prop );
5393 return it != type->properties.end() ? it->second : def;
5394}

References itype::properties, and type.

Referenced by iuse::capture_monster_act().

◆ get_qualities()

std::map< quality_id, int > item::get_qualities ( ) const

Definition at line 5457 of file item.cpp.

5458{
5459 std::map<quality_id, int> qualities;
5460 for( const auto &quality : type->qualities ) {
5461 qualities[quality.first] = get_quality( quality.first );
5462 }
5463 return qualities;
5464}
int get_quality(const quality_id &id) const
Definition: item.cpp:5410
std::map< quality_id, int > qualities
Definition: itype.h:885

References get_quality(), itype::qualities, and type.

Referenced by inventory::update_quality_cache().

◆ get_quality()

int item::get_quality ( const quality_id id) const

EXCEPTION: Items with quality BOIL only count as such if they are empty, excluding items of their ammo type if they are tools.

Definition at line 5410 of file item.cpp.

5411{
5412 int return_quality = INT_MIN;
5413
5414 /**
5415 * EXCEPTION: Items with quality BOIL only count as such if they are empty,
5416 * excluding items of their ammo type if they are tools.
5417 */
5418 auto block_boil_filter = [this]( const item & itm ) {
5419 // We want to skip (do not block) only those : correct ammo, correct magazine, correct toolmod.Everything else should block.
5420 if( &itm == this ) {
5421 // Do not block if checking itself - we are checking only item contents not item itself.
5422 return false;
5423 } else if( itm.is_ammo() ) {
5424 return ammo_types().count( itm.ammo_type() ) == 0;
5425 } else if( itm.is_magazine() ) {
5426 // we want to return "fine for boiling" if any of the ammo types match and "blocks boiling" if none match.
5427 for( const ammotype &at : ammo_types() ) {
5428 for( const ammotype &mag_at : itm.ammo_types() ) {
5429 if( at == mag_at ) {
5430 return false;
5431 }
5432 }
5433 }
5434 return true;
5435 } else if( itm.is_toolmod() ) {
5436 return false;
5437 }
5438 return true;
5439 };
5440 // if it's has boil quality and it's empty, it's good to boil. If it's not empty and it's not a tool (it's probably a container), it's not good to boil. If it's a tool, it gets an extra chance: if it's only contents are mods or batteries, it's still good.
5441 // Also we are using inverted filter, since we don't care about items that the filter likes, we only care if it find something it doesn't like.
5442 if( id == quality_id( "BOIL" ) && !contents.empty() &&
5443 ( !is_tool() || has_item_with( block_boil_filter ) ) ) {
5444 return INT_MIN;
5445 }
5446
5447 for( const std::pair<const quality_id, int> &quality : type->qualities ) {
5448 if( quality.first == id ) {
5449 return_quality = quality.second;
5450 }
5451 }
5452 return_quality = std::max( return_quality, contents.best_quality( id ) );
5453
5454 return return_quality;
5455}
int best_quality(const quality_id &id) const
string_id< quality > quality_id
Definition: type_id.h:184

References ammo_types(), item_contents::best_quality(), contents, item_contents::empty(), visitable< item >::has_item_with(), is_tool(), itype::qualities, and type.

Referenced by iuse::clear_rubble(), iuse::crowbar(), dig_pit_moves_and_byproducts(), get_qualities(), bionic::get_quality(), has_quality_internal(), Character::item_with_best_of_quality(), activity_handlers::lockpicking_finish(), max_quality_internal(), and pick_lock_actor::use().

◆ get_random_material()

const material_type & item::get_random_material ( ) const

Get a material reference to a random material that this item is made of.

This might return the null-material, you may check this with material_type::ident. Note that this may also return a different material each time it's invoked (if the item is made from several materials).

Definition at line 7156 of file item.cpp.

7157{
7158 return random_entry( made_of(), material_id::NULL_ID() ).obj();
7159}
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88

References made_of(), string_id< material_type >::NULL_ID(), and random_entry().

Referenced by Character::armor_absorb().

◆ get_relative_health()

float item::get_relative_health ( ) const

Relative item health.

Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items and values above 1 for reinforced ++items.

Definition at line 6231 of file item.cpp.

6232{
6233 return ( max_damage() + 1.0f - damage() ) / ( max_damage() + 1.0f );
6234}

References damage(), and max_damage().

Referenced by get_base_env_resist(), and get_env_resist().

◆ get_relative_rot()

double item::get_relative_rot ( ) const

Get rot value relative to shelf life (or 0 if item does not spoil)

Definition at line 5558 of file item.cpp.

5559{
5560 if( goes_bad() ) {
5561 return rot / get_shelf_life();
5562 }
5563 return 0;
5564}
Definition: rot.cpp:12

References get_shelf_life(), and goes_bad().

Referenced by Character::consume_effects(), fill_with(), Character::fun_for(), comestible_inventory_preset::get_freshness(), get_freshness_description(), get_most_rotten_component(), comestible_inventory_preset::get_time_left(), has_rotten_away(), item(), and rate_food().

◆ get_relic_recharge_scheme()

const std::vector< relic_recharge > & item::get_relic_recharge_scheme ( ) const

Definition at line 7035 of file item.cpp.

7036{
7037 return relic_data->get_recharge_scheme();
7038}

References relic_data.

Referenced by relic_funcs::process_recharge().

◆ get_reload_time()

int item::get_reload_time ( ) const

Returns the reload time of the gun.

Returns 0 if not a gun.

Definition at line 6538 of file item.cpp.

6539{
6540 if( !is_gun() && !is_magazine() ) {
6541 return 0;
6542 }
6543
6544 int reload_time = is_gun() ? type->gun->reload_time : type->magazine->reload_time;
6545 for( const item *mod : gunmods() ) {
6546 reload_time = static_cast<int>( reload_time * ( 100 + mod->type->gunmod->reload_modifier ) / 100 );
6547 }
6548
6549 return reload_time;
6550}

References itype::gun, gunmods(), is_gun(), is_magazine(), itype::magazine, and type.

Referenced by ideal_ranged_dps(), Character::item_reload_cost(), and item_reload_option::moves().

◆ get_remaining_capacity_for_liquid() [1/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
bool  allow_bucket = false,
std::string *  err = nullptr 
) const

How much more of this liquid (in charges) can be put in this container.

If this is not a container (or not suitable for the liquid), it returns 0. Note that mixing different types of liquid is not possible. Also note that this works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to check capacity for
allow_bucketAllow filling non-sealable containers
errMessage to print if no more material will fit

Definition at line 8431 of file item.cpp.

8433{
8434 const auto error = [ &err ]( const std::string & message ) {
8435 if( err != nullptr ) {
8436 *err = message;
8437 }
8438 return 0;
8439 };
8440
8441 int remaining_capacity = 0;
8442
8443 // TODO: (sm) is_reloadable_with and this function call each other and can recurse for
8444 // watertight containers.
8445 if( !is_container() && is_reloadable_with( liquid.typeId() ) ) {
8446 if( ammo_remaining() != 0 && ammo_current() != liquid.typeId() ) {
8447 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8448 }
8449 remaining_capacity = ammo_capacity() - ammo_remaining();
8450 } else if( is_container() ) {
8451 if( !type->container->watertight ) {
8452 return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
8453 } else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
8454 return error( string_format( is_bucket() ?
8455 _( "That %s must be on the ground or held to hold contents!" )
8456 : _( "You can't seal that %s!" ), tname() ) );
8457 } else if( !contents.empty() && contents.front().typeId() != liquid.typeId() ) {
8458 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8459 }
8460 remaining_capacity = liquid.charges_per_volume( get_container_capacity() );
8461 if( !contents.empty() ) {
8462 remaining_capacity -= contents.front().charges;
8463 }
8464 } else {
8465 return error( string_format( _( "That %1$s won't hold %2$s." ), tname(),
8466 liquid.tname() ) );
8467 }
8468
8469 if( remaining_capacity <= 0 ) {
8470 return error( string_format( _( "Your %1$s can't hold any more %2$s." ), tname(),
8471 liquid.tname() ) );
8472 }
8473
8474 return remaining_capacity;
8475}
std::string message
Definition: mapgen.cpp:420

References _, ammo_capacity(), ammo_current(), ammo_remaining(), charges, charges_per_volume(), itype::container, contents, item_contents::empty(), detail::digits::error, item_contents::front(), get_container_capacity(), is_bucket(), is_container(), is_reloadable_with(), mapgen_defer::message, string_format(), tname(), type, and typeId().

Referenced by add_rain_to_container(), fill_with(), get_remaining_capacity_for_liquid(), is_container_full(), maple_tree_sap_container(), advanced_inventory::move_content(), Character::pour_into(), item_reload_option::qty(), and reload().

◆ get_remaining_capacity_for_liquid() [2/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
const Character p,
std::string *  err = nullptr 
) const

Definition at line 8477 of file item.cpp.

8479{
8480 const bool allow_bucket = p.is_wielding( *this ) || !p.has_item( *this );
8481 int res = get_remaining_capacity_for_liquid( liquid, allow_bucket, err );
8482
8483 if( res > 0 && !type->rigid && p.inv.has_item( *this ) ) {
8484 const units::volume volume_to_expand = std::max( p.volume_capacity() - p.volume_carried(),
8485 0_ml );
8486
8487 res = std::min( liquid.charges_per_volume( volume_to_expand ), res );
8488
8489 if( res == 0 && err != nullptr ) {
8490 *err = string_format( _( "That %s doesn't have room to expand." ), tname() );
8491 }
8492 }
8493
8494 return res;
8495}
units::volume volume_capacity() const
Definition: character.cpp:2671
bool is_wielding(const item &target) const
Definition: character.cpp:3230
units::volume volume_carried() const
Definition: character.cpp:2543

References _, charges_per_volume(), get_remaining_capacity_for_liquid(), visitable< T >::has_item(), Character::inv, Character::is_wielding(), itype::rigid, string_format(), tname(), type, Character::volume_capacity(), and Character::volume_carried().

◆ get_remaining_chapters()

int item::get_remaining_chapters ( const Character ch) const

Get the number of unread chapters.

If the item is no book or has no chapters, it returns 0. This is a per-character setting, different characters may have different number of unread chapters.

Definition at line 7107 of file item.cpp.

7108{
7109 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7110 return get_var( var, get_chapters() );
7111}

References get_chapters(), character_id::get_value(), get_var(), Character::getID(), and string_format().

Referenced by book_info(), display_name(), character_funcs::get_book_fun_for(), and mark_chapter_as_read().

◆ get_rot()

time_duration item::get_rot ( ) const
inline

Definition at line 860 of file item.h.

860 {
861 return rot;
862 }

Referenced by butchery_drops_harvest(), and has_rotten_away().

◆ get_safe_reference()

safe_reference< item > item::get_safe_reference ( )

Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to.

Definition at line 451 of file item.cpp.

452{
453 return anchor.reference_to( this );
454}
safe_reference_anchor anchor
Definition: item.h:2179
safe_reference< T > reference_to(T *object)

References anchor, and safe_reference_anchor::reference_to().

Referenced by active_item_cache::add(), and explosion_handler::ExplosionProcess::move_entity().

◆ get_shelf_life()

time_duration item::get_shelf_life ( ) const

Get the shelf life of the item.

Definition at line 5546 of file item.cpp.

5547{
5548 if( goes_bad() ) {
5549 if( is_food() ) {
5550 return get_comestible()->spoils;
5551 } else if( is_corpse() ) {
5552 return 24_hours;
5553 }
5554 }
5555 return 0_turns;
5556}

References get_comestible(), goes_bad(), is_corpse(), and is_food().

Referenced by basic_info(), food_info(), get_freshness_description(), get_relative_rot(), process_corpse(), set_relative_rot(), spoilage_sort_order(), and stacks_with().

◆ get_side()

side item::get_side ( ) const

Returns side item currently worn on.

Returns BOTH if item is not sided or no side currently set

Definition at line 813 of file item.cpp.

814{
815 // MSVC complains if directly cast double to enum
816 return static_cast<side>( static_cast<int>( get_var( "lateral",
817 static_cast<int>( side::BOTH ) ) ) );
818}
side
Definition: bodypart.h:68

References BOTH, and get_var().

Referenced by display_name(), get_covered_body_parts(), on_wear(), and swap_side().

◆ get_sizing()

item::sizing item::get_sizing ( const Character p,
bool  wearable 
) const

Definition at line 1182 of file item.cpp.

1183{
1184 if( wearable ) {
1185 const bool small = p.get_size() == MS_TINY;
1186 const bool big = p.get_size() == MS_HUGE;
1187
1188 // due to the iterative nature of these features, something can fit and be undersized/oversized
1189 // but that is fine because we have separate logic to adjust encumberance per each. One day we
1190 // may want to have fit be a flag that only applies if a piece of clothing is sized for you as there
1191 // is a bit of cognitive dissonance when something 'fits' and is 'oversized' and the same time
1192 const bool undersize = has_flag( flag_UNDERSIZE );
1193 const bool oversize = has_flag( flag_OVERSIZE );
1194
1195 if( undersize ) {
1196 if( small ) {
1198 } else if( big ) {
1200 } else {
1202 }
1203 } else if( oversize ) {
1204 if( big ) {
1206 } else if( small ) {
1208 } else {
1210 }
1211 } else {
1212 if( big ) {
1214 } else if( small ) {
1216 } else {
1218 }
1219 }
1220 }
1221 return sizing::not_wearable;
1222
1223}
m_size get_size() const override
Get size class of character.
Definition: character.cpp:575
@ MS_TINY
Definition: creature.h:58
@ MS_HUGE
Definition: creature.h:62
static const std::string flag_UNDERSIZE("UNDERSIZE")
static const std::string flag_OVERSIZE("OVERSIZE")

References big_sized_big_char, big_sized_human_char, big_sized_small_char, flag_OVERSIZE(), flag_UNDERSIZE(), Character::get_size(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, MS_HUGE, MS_TINY, not_wearable, small_sized_big_char, small_sized_human_char, and small_sized_small_char.

Referenced by armor_fit_info(), armor_info(), get_encumber_when_containing(), and tname().

◆ get_storage()

units::volume item::get_storage ( ) const

Returns the storage amount (islot_armor::storage) that this item provides when worn.

For non-armor it returns 0. The storage amount increases the volume capacity of the character that wears the item.

Definition at line 5742 of file item.cpp.

5743{
5744 const islot_armor *t = find_armor_data();
5745 if( t == nullptr ) {
5746 return is_pet_armor() ? type->pet_armor->storage : 0_ml;
5747 }
5748 units::volume storage = t->storage;
5750 storage += std::lround( mod ) * units::legacy_volume_factor;
5751
5752 return storage;
5753}
@ clothing_mod_type_storage
Definition: clothing_mod.h:24

References clothing_mod_type_storage, find_armor_data(), get_clothing_mod_val(), is_pet_armor(), units::legacy_volume_factor, itype::pet_armor, islot_armor::storage, and type.

Referenced by animal_armor_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), get_encumber(), get_total_capacity(), monexamine::give_items_to(), pickup::obtain_and_tokenize_items(), om_carry_weight_to_trips(), tutorial_game::post_action(), pickup::reorder_for_dropping(), Character::takeoff(), and sew_advanced_actor::use().

◆ get_techniques()

std::set< matec_id > item::get_techniques ( ) const

Returns all the martial art techniques that this items supports.

Definition at line 5502 of file item.cpp.

5503{
5504 std::set<matec_id> result = type->techniques;
5505 result.insert( techniques.begin(), techniques.end() );
5506 return result;
5507}

References techniques, itype::techniques, and type.

Referenced by character_martial_arts::get_all_techniques().

◆ get_thickness()

int item::get_thickness ( ) const

Returns the islot_armor::thickness value, or 0 for non-armor.

Thickness is are relative value that affects the items resistance against bash / cutting / bullet damage.

Definition at line 5919 of file item.cpp.

5920{
5921 const islot_armor *t = find_armor_data();
5922 if( t == nullptr ) {
5923 return is_pet_armor() ? type->pet_armor->thickness : 0;
5924 }
5925 return t->thickness;
5926}
int thickness
TODO: document me.
Definition: itype.h:260

References find_armor_data(), is_pet_armor(), itype::pet_armor, islot_armor::thickness, and type.

Referenced by bash_resist(), bullet_resist(), cut_resist(), clothing_mod::get_mod_val(), and tutorial_game::post_action().

◆ get_total_capacity()

units::volume item::get_total_capacity ( ) const

It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc.

Definition at line 8410 of file item.cpp.

8411{
8413
8414 // Consider various iuse_actors which add containing capability
8415 // Treating these two as special cases for now; if more appear in the
8416 // future then this probably warrants a new method on use_function to
8417 // access this information generically.
8418 if( is_bandolier() ) {
8419 result += dynamic_cast<const bandolier_actor *>
8420 ( type->get_use( "bandolier" )->get_actor_ptr() )->max_stored_volume();
8421 }
8422
8423 if( is_holster() ) {
8424 result += dynamic_cast<const holster_actor *>
8425 ( type->get_use( "holster" )->get_actor_ptr() )->max_stored_volume();
8426 }
8427
8428 return result;
8429}
bool is_holster() const
Definition: item.cpp:6587

References use_function::get_actor_ptr(), get_container_capacity(), get_storage(), itype::get_use(), is_bandolier(), is_holster(), and type.

Referenced by armor_info(), and get_encumber_when_containing().

◆ get_uncraft_components()

std::vector< item_comp > item::get_uncraft_components ( ) const

Returns a list of components used to craft this item or the default components if it wasn't player-crafted.

Definition at line 10064 of file item.cpp.

10065{
10066 std::vector<item_comp> ret;
10067 if( components.empty() ) {
10068 //If item wasn't crafted with specific components use default recipe
10069 std::vector<std::vector<item_comp>> recipe = recipe_dictionary::get_uncraft(
10071 for( std::vector<item_comp> &component : recipe ) {
10072 ret.push_back( component.front() );
10073 }
10074 } else {
10075 //Make a new vector of components from the registered components
10076 for( const item &component : components ) {
10077 auto iter = std::find_if( ret.begin(), ret.end(), [component]( item_comp & obj ) {
10078 return obj.type == component.typeId();
10079 } );
10080
10081 if( iter != ret.end() ) {
10082 iter->count += component.count();
10083 } else {
10084 ret.push_back( item_comp( component.typeId(), component.count() ) );
10085 }
10086 }
10087 }
10088 return ret;
10089}

References components, component::count, recipe::disassembly_requirements(), requirement_data::get_components(), recipe_dictionary::get_uncraft(), cata::hash64_detail::ret, and typeId().

Referenced by disassemble_inventory_preset::disassemble_inventory_preset(), and stacks_with().

◆ get_usable_item()

item * item::get_usable_item ( const std::string &  use_name)

Checks this item and its contents (recursively) for types that have use_function with type use_name.

Returns the first item that does have such type or nullptr if none found.

Definition at line 7975 of file item.cpp.

7976{
7977 item *ret = nullptr;
7979 [&ret, &use_name]( item * it ) {
7980 if( it == nullptr ) {
7981 return VisitResponse::SKIP;
7982 }
7983 if( it->get_use_internal( use_name ) ) {
7984 ret = it;
7985 return VisitResponse::ABORT;
7986 }
7987 return VisitResponse::NEXT;
7988 } );
7989
7990 return ret;
7991}
const use_function * get_use_internal(const std::string &use_name) const
Definition: item.cpp:7967

References get_use_internal(), NEXT, cata::hash64_detail::ret, SKIP, and visitable< item >::visit_items().

Referenced by game::butcher(), activity_handlers::firstaid_finish(), Character::invoke_item(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), activity_handlers::repair_item_finish(), and activity_handlers::start_fire_finish().

◆ get_use()

const use_function * item::get_use ( const std::string &  use_name) const

Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents.

Checks contents recursively. Returns nullptr if not found.

Definition at line 7949 of file item.cpp.

7950{
7951 const use_function *fun = nullptr;
7953 [&fun, &use_name]( const item * it ) {
7954 if( it == nullptr ) {
7955 return VisitResponse::SKIP;
7956 }
7957 fun = it->get_use_internal( use_name );
7958 if( fun != nullptr ) {
7959 return VisitResponse::ABORT;
7960 }
7961 return VisitResponse::NEXT;
7962 } );
7963
7964 return fun;
7965}

References ABORT, get_use_internal(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by active_item_cache::add(), game::butcher(), color_in_inventory(), activity_handlers::firstaid_finish(), iuse_transform::info(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), on_takeoff(), on_wear(), process_tool(), read(), active_item_cache::remove(), activity_handlers::repair_item_finish(), sleep(), activity_handlers::start_fire_finish(), avatar::wield(), avatar_action::wield(), and npc::wield_better_weapon().

◆ get_use_internal()

const use_function * item::get_use_internal ( const std::string &  use_name) const
private

Definition at line 7967 of file item.cpp.

7968{
7969 if( type != nullptr ) {
7970 return type->get_use( use_name );
7971 }
7972 return nullptr;
7973}

References itype::get_use(), and type.

Referenced by get_usable_item(), and get_use().

◆ get_var() [1/4]

std::string item::get_var ( const std::string &  name) const

Get the variable, if it does not exists, returns an empty string.

Definition at line 1075 of file item.cpp.

1076{
1077 return get_var( name, "" );
1078}

References get_var(), and om_direction::name().

◆ get_var() [2/4]

std::string item::get_var ( const std::string &  name,
const std::string &  default_value 
) const

Definition at line 1066 of file item.cpp.

1067{
1068 const auto it = item_vars.find( name );
1069 if( it == item_vars.end() ) {
1070 return default_value;
1071 }
1072 return it->second;
1073}

References item_vars, and om_direction::name().

◆ get_var() [3/4]

tripoint item::get_var ( const std::string &  name,
const tripoint default_value 
) const

Definition at line 1049 of file item.cpp.

1050{
1051 const auto it = item_vars.find( name );
1052 if( it == item_vars.end() ) {
1053 return default_value;
1054 }
1055 std::vector<std::string> values = string_split( it->second, ',' );
1056 return tripoint( atoi( values[0].c_str() ),
1057 atoi( values[1].c_str() ),
1058 atoi( values[2].c_str() ) );
1059}
std::vector< std::string > string_split(const std::string &text_in, char delim_in)
Split string by delimiter.

References item_vars, om_direction::name(), and string_split().

◆ get_var() [4/4]

◆ get_warmth()

int item::get_warmth ( ) const

Returns the warmth value that this item has when worn.

See player class for temperature related code, or player::warmth. Returned values should be positive. A value of 0 indicates no warmth from this item at all (this is also the default for non-armor).

Definition at line 5928 of file item.cpp.

5929{
5930 const islot_armor *t = find_armor_data();
5931 if( t == nullptr ) {
5932 return 0;
5933 }
5934 int result = t->warmth;
5935
5937
5938 return result;
5939}
@ clothing_mod_type_warmth
Definition: clothing_mod.h:23
int warmth
How much warmth this item provides.
Definition: itype.h:272

References clothing_mod_type_warmth, find_armor_data(), get_clothing_mod_val(), and islot_armor::warmth.

Referenced by armor_info(), armor_inventory_preset::armor_inventory_preset(), behavior::character_oracle_t::can_wear_warmer_clothes(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), sew_advanced_actor::use(), and Character::warmth().

◆ get_weight_capacity_bonus()

units::mass item::get_weight_capacity_bonus ( ) const

Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.

Definition at line 5764 of file item.cpp.

5765{
5766 const islot_armor *t = find_armor_data();
5767 if( t == nullptr ) {
5768 return 0_gram;
5769 }
5770 return t->weight_capacity_bonus;
5771}
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: itype.h:284

References find_armor_data(), and islot_armor::weight_capacity_bonus.

Referenced by armor_info().

◆ get_weight_capacity_modifier()

float item::get_weight_capacity_modifier ( ) const

Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.

Definition at line 5755 of file item.cpp.

5756{
5757 const islot_armor *t = find_armor_data();
5758 if( t == nullptr ) {
5759 return 1;
5760 }
5761 return t->weight_capacity_modifier;
5762}
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: itype.h:280

References find_armor_data(), and islot_armor::weight_capacity_modifier.

Referenced by armor_info().

◆ getlight()

bool item::getlight ( float &  luminance,
units::angle width,
units::angle direction 
) const

Directional light emission of the item.

Parameters
luminanceThe amount of light (see lightmap.cpp)
widthIf greater 0, the light is emitted in an arc, this is the angle of it.
directionThe direction of the light arc. In degrees.

Definition at line 8364 of file item.cpp.

8365{
8366 luminance = 0;
8367 width = 0_degrees;
8368 direction = 0_degrees;
8369 if( light.luminance > 0 ) {
8370 luminance = static_cast<float>( light.luminance );
8371 if( light.width > 0 ) { // width > 0 is a light arc
8372 width = units::from_degrees( light.width );
8374 }
8375 return true;
8376 } else {
8377 const int lumint = getlight_emit();
8378 if( lumint > 0 ) {
8379 luminance = static_cast<float>( lumint );
8380 return true;
8381 }
8382 }
8383 return false;
8384}
light_emission light
Definition: item.h:2243
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8386
direction
Definition: line.h:39
constexpr quantity< double, angle_in_radians_tag > from_degrees(const value_type v)
Definition: units_angle.h:31
unsigned short luminance
Definition: item.h:89
short direction
Definition: item.h:91
short width
Definition: item.h:90

References light_emission::direction, units::from_degrees(), getlight_emit(), light, light_emission::luminance, and light_emission::width.

◆ getlight_emit()

int item::getlight_emit ( ) const

How much light (see lightmap.cpp) the item emits (it's assumed to be circular).

Definition at line 8386 of file item.cpp.

8387{
8388 float lumint = type->light_emission;
8389
8390 if( lumint == 0 ) {
8391 return 0;
8392 }
8393 if( has_flag( flag_CHARGEDIM ) && is_tool() && !has_flag( flag_USE_UPS ) ) {
8394 // Falloff starts at 1/5 total charge and scales linearly from there to 0.
8395 if( ammo_capacity() && ammo_remaining() < ( ammo_capacity() / 5 ) ) {
8396 lumint *= ammo_remaining() * 5.0 / ammo_capacity();
8397 }
8398 }
8399 return lumint;
8400}
static const std::string flag_CHARGEDIM("CHARGEDIM")
unsigned light_emission
Definition: itype.h:971

References ammo_capacity(), ammo_remaining(), flag_CHARGEDIM(), flag_USE_UPS(), has_flag(), is_tool(), itype::light_emission, and type.

Referenced by Character::active_light(), and getlight().

◆ goes_bad()

bool item::goes_bad ( ) const

whether an item is perishable (can rot)

Definition at line 5525 of file item.cpp.

5526{
5529 }
5530 if( has_flag( flag_PROCESSING ) ) {
5531 return false;
5532 }
5533 if( is_corpse() ) {
5534 // Corpses rot only if they are made of rotting materials
5536 }
5537 return is_food() && get_comestible()->spoils != 0_turns;
5538}
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6445
static const std::string flag_PROCESSING("PROCESSING")
bool goes_bad_cache_fetch()
Definition: item.cpp:339
bool goes_bad_cache_is_for(const item *i)
Definition: item.cpp:353
std::set< material_id > get_rotting()
Definition: material.cpp:327

References flag_PROCESSING(), get_comestible(), materials::get_rotting(), item_internal::goes_bad_cache_fetch(), item_internal::goes_bad_cache_is_for(), has_flag(), is_corpse(), is_food(), and made_of_any().

Referenced by actualize_rot(), basic_info(), crafting::can_disassemble(), complete_craft(), food_info(), get_most_rotten_component(), get_relative_rot(), get_shelf_life(), goes_bad_after_opening(), item_internal::goes_bad_cache_set(), item(), set_relative_rot(), spoilage_sort_order(), stacks_with(), and tname().

◆ goes_bad_after_opening()

bool item::goes_bad_after_opening ( ) const

whether an item is perishable (can rot), even if it is currently in a preserving container

Definition at line 5540 of file item.cpp.

5541{
5542 return goes_bad() || ( type->container && type->container->preserves &&
5543 !contents.empty() && contents.front().goes_bad() );
5544}

References itype::container, contents, item_contents::empty(), item_contents::front(), goes_bad(), and type.

◆ gun_all_modes()

std::map< gun_mode_id, gun_mode > item::gun_all_modes ( ) const

Get all possible modes for this gun inclusive of any attached gunmods.

Definition at line 7840 of file item.cpp.

7841{
7842 std::map<gun_mode_id, gun_mode> res;
7843
7844 if( !is_gun() || is_gunmod() ) {
7845 return res;
7846 }
7847
7848 std::vector<const item *> opts = gunmods();
7849 opts.push_back( this );
7850
7851 for( const item *e : opts ) {
7852
7853 // handle base item plus any auxiliary gunmods
7854 if( e->is_gun() ) {
7855 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gun->modes ) {
7856 // prefix attached gunmods, e.g. M203_DEFAULT to avoid index key collisions
7857 std::string prefix = e->is_gunmod() ? ( std::string( e->typeId() ) += "_" ) : "";
7858 std::transform( prefix.begin(), prefix.end(), prefix.begin(),
7859 static_cast<int( * )( int )>( toupper ) );
7860
7861 const int qty = m.second.qty();
7862
7863 res.emplace( gun_mode_id( prefix + m.first.str() ), gun_mode( m.second.name(),
7864 const_cast<item *>( e ),
7865 qty, m.second.flags() ) );
7866 }
7867
7868 // non-auxiliary gunmods may provide additional modes for the base item
7869 } else if( e->is_gunmod() ) {
7870 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gunmod->mode_modifier ) {
7871 //checks for melee gunmod, points to gunmod
7872 if( m.first == gun_mode_REACH ) {
7873 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( e ),
7874 m.second.qty(), m.second.flags() } );
7875 //otherwise points to the parent gun, not the gunmod
7876 } else {
7877 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( this ),
7878 m.second.qty(), m.second.flags() } );
7879 }
7880 }
7881 }
7882 }
7883
7884 return res;
7885}
static const gun_mode_id gun_mode_REACH("REACH")
string_id< gun_mode > gun_mode_id
Definition: type_id.h:68

References gun_mode_REACH, gunmods(), is_gun(), is_gunmod(), prefix, and iexamine::transform().

Referenced by target_ui::action_switch_mode(), npc_ai::best_mode_for_range(), can_fire_turret(), npc::confident_shoot_range(), gun_cycle_mode(), gun_get_mode(), gun_set_mode(), game::handle_action(), and reach_range().

◆ gun_current_mode()

gun_mode item::gun_current_mode ( ) const

Get the current mode for this gun (or an invalid mode if item is not a gun)

Definition at line 7899 of file item.cpp.

7900{
7901 return gun_get_mode( gun_get_mode_id() );
7902}
gun_mode_id gun_get_mode_id() const
Get id of mode a gun is currently set to, e.g.
Definition: item.cpp:7904
gun_mode gun_get_mode(const gun_mode_id &mode) const
Check if gun supports a specific mode returning an invalid/empty mode if not.
Definition: item.cpp:7887

References gun_get_mode(), and gun_get_mode_id().

Referenced by avatar_action::can_fire_weapon(), aim_activity_actor::do_turn(), target_ui::ensure_ranged_gun_mode(), npc::execute_action(), aim_activity_actor::finish(), fire(), turret_data::fire(), character_funcs::fmt_wielded_weapon(), info(), aim_activity_actor::load_RAS_weapon(), npc::method_of_attack(), target_ui::panel_fire_mode_aim(), target_ui::panel_gun_info(), turret_data::post_fire(), turret_data::prepare_fire(), print_aim(), turret_data::query(), gun_actor::shoot(), target_ui::update_ammo_range_from_gun_mode(), and target_ui::update_status().

◆ gun_cycle_mode()

void item::gun_cycle_mode ( )

Switch to the next available firing mode.

Definition at line 7921 of file item.cpp.

7922{
7923 if( !is_gun() || is_gunmod() ) {
7924 return;
7925 }
7926
7927 const gun_mode_id cur = gun_get_mode_id();
7928 const std::map<gun_mode_id, gun_mode> modes = gun_all_modes();
7929
7930 for( auto iter = modes.begin(); iter != modes.end(); ++iter ) {
7931 if( iter->first == cur ) {
7932 if( std::next( iter ) == modes.end() ) {
7933 break;
7934 }
7935 gun_set_mode( std::next( iter )->first );
7936 return;
7937 }
7938 }
7939 gun_set_mode( modes.begin()->first );
7940
7941 return;
7942}
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7840
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7912

References gun_all_modes(), gun_get_mode_id(), gun_set_mode(), is_gun(), and is_gunmod().

Referenced by target_ui::ensure_ranged_gun_mode(), and game::handle_action().

◆ gun_damage()

damage_instance item::gun_damage ( bool  with_ammo = true) const

Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.

Returns empty instance on non-gun items.

Definition at line 7277 of file item.cpp.

7278{
7279 if( !is_gun() ) {
7280 return damage_instance();
7281 }
7282 damage_instance ret = type->gun->damage;
7283
7284 for( const item *mod : gunmods() ) {
7285 ret.add( mod->type->gunmod->damage );
7286 }
7287
7288 if( with_ammo && ammo_data() ) {
7289 ret.add( ammo_data()->ammo->damage );
7290 }
7291
7292 int item_damage = damage_level( 4 );
7293 if( item_damage > 0 ) {
7294 // TODO: This isn't a good solution for multi-damage guns/ammos
7295 for( damage_unit &du : ret ) {
7296 if( du.amount <= 1.0 ) {
7297 continue;
7298 }
7299 du.amount = std::max<float>( 1.0f, du.amount - item_damage * 2 );
7300 }
7301 }
7302
7303 return ret;
7304}

References ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), cata::hash64_detail::ret, and type.

Referenced by gun_info(), ideal_ranged_dps(), make_gun_projectile(), and weapon_inventory_preset::weapon_inventory_preset().

◆ gun_dispersion()

int item::gun_dispersion ( bool  with_ammo = true,
bool  with_scaling = true 
) const

Summed dispersion of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7230 of file item.cpp.

7231{
7232 if( !is_gun() ) {
7233 return 0;
7234 }
7235 int dispersion_sum = type->gun->dispersion;
7236 for( const item *mod : gunmods() ) {
7237 dispersion_sum += mod->type->gunmod->dispersion;
7238 }
7239 int dispPerDamage = get_option< int >( "DISPERSION_PER_GUN_DAMAGE" );
7240 dispersion_sum += damage_level( 4 ) * dispPerDamage;
7241 dispersion_sum = std::max( dispersion_sum, 0 );
7242 if( with_ammo && ammo_data() ) {
7243 dispersion_sum += ammo_data()->ammo->dispersion;
7244 }
7245 if( !with_scaling ) {
7246 return dispersion_sum;
7247 }
7248
7249 // Dividing dispersion by 15 temporarily as a gross adjustment,
7250 // will bake that adjustment into individual gun definitions in the future.
7251 // Absolute minimum gun dispersion is 1.
7252 double divider = get_option< float >( "GUN_DISPERSION_DIVIDER" );
7253 dispersion_sum = std::max( static_cast<int>( std::round( dispersion_sum / divider ) ), 1 );
7254
7255 return dispersion_sum;
7256}

References itype::ammo, ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), and type.

Referenced by gun_info().

◆ gun_get_mode()

gun_mode item::gun_get_mode ( const gun_mode_id mode) const

Check if gun supports a specific mode returning an invalid/empty mode if not.

Definition at line 7887 of file item.cpp.

7888{
7889 if( is_gun() ) {
7890 for( const std::pair<const gun_mode_id, gun_mode> &e : gun_all_modes() ) {
7891 if( e.first == mode ) {
7892 return e.second;
7893 }
7894 }
7895 }
7896 return gun_mode();
7897}

References gun_all_modes(), and is_gun().

Referenced by mattack::frag(), gun_current_mode(), mattack::rifle(), and mattack::tankgun().

◆ gun_get_mode_id()

gun_mode_id item::gun_get_mode_id ( ) const

Get id of mode a gun is currently set to, e.g.

DEFAULT, AUTO, BURST

Definition at line 7904 of file item.cpp.

7905{
7906 if( !is_gun() || is_gunmod() ) {
7907 return gun_mode_id();
7908 }
7909 return gun_mode_id( get_var( GUN_MODE_VAR_NAME, "DEFAULT" ) );
7910}
static const std::string GUN_MODE_VAR_NAME("item::mode")

References get_var(), GUN_MODE_VAR_NAME(), is_gun(), and is_gunmod().

Referenced by target_ui::action_switch_mode(), gun_current_mode(), and gun_cycle_mode().

◆ gun_info()

void item::gun_info ( const item mod,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2022 of file item.cpp.

2024{
2025 const std::string space = " ";
2026 const islot_gun &gun = *mod->type->gun;
2027 const Skill &skill = *mod->gun_skill();
2028 avatar &viewer = get_avatar();
2029
2030 // many statistics are dependent upon loaded ammo
2031 // if item is unloaded (or is RELOAD_AND_SHOOT) shows approximate stats using default ammo
2032 const item *loaded_mod = mod;
2033 item tmp;
2034 if( mod->ammo_required() && !mod->ammo_remaining() ) {
2035 tmp = *mod;
2036 tmp.ammo_set( mod->magazine_current() ? tmp.common_ammo_default() : tmp.ammo_default() );
2037 if( tmp.ammo_data() == nullptr ) {
2039 info.emplace_back( "GUN",
2040 _( "Weapon <bad>can't be loaded in its current state</bad>." ) );
2041 return;
2042 }
2043 loaded_mod = &tmp;
2044 if( parts->test( iteminfo_parts::GUN_DEFAULT_AMMO ) ) {
2046 info.emplace_back( "GUN",
2047 _( "Weapon is <bad>not loaded</bad>, so stats below assume the default ammo: " ),
2048 string_format( "<stat>%s</stat>",
2049 loaded_mod->ammo_data()->nname( 1 ) ) );
2050 }
2051 }
2052
2053 const itype *curammo = loaded_mod->ammo_data();
2054 if( mod->ammo_required() && !curammo ) {
2055 debugmsg( "curammo is nullptr in item::gun_info()" );
2056 return;
2057 }
2058 damage_unit gun_du = gun_damage( false ).damage_units.front();
2059
2061
2062 const damage_unit &ammo_du = curammo != nullptr
2063 ? curammo->ammo->damage.damage_units.front()
2064 : damage_unit( DT_STAB, 0 );
2065
2066 if( parts->test( iteminfo_parts::GUN_DAMAGE ) ) {
2068 info.push_back( iteminfo( "GUN", _( "<bold>Ranged damage</bold>: " ), "", iteminfo::no_newline,
2069 gun_du.amount ) );
2070 }
2071
2072 if( mod->ammo_required() ) {
2073 // ammo_damage, sum_of_damage, and ammo_mult not shown so don't need to translate.
2075 assert( curammo ); // Appease clang-tidy
2076 damage_instance ammo_dam = curammo->ammo->damage;
2077 info.push_back( iteminfo( "GUN", "ammo_damage", "",
2079 iteminfo::show_plus, ammo_du.amount ) );
2080 }
2081
2082 if( parts->test( iteminfo_parts::GUN_DAMAGE_TOTAL ) ) {
2083 // Intentionally not using total_damage() as it applies multipliers
2084 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2086 gun_du.amount + ammo_du.amount ) );
2087 }
2088 }
2089 info.back().bNewLine = true;
2090 avatar &you = get_avatar();
2091 int max_gun_range = loaded_mod->gun_range( &you );
2092 if( max_gun_range > 0 && parts->test( iteminfo_parts::GUN_MAX_RANGE ) ) {
2093 info.emplace_back( "GUN", _( "Maximum range: " ), "<num>", iteminfo::no_flags,
2094 max_gun_range );
2095 }
2096
2097 // TODO: This doesn't cover multiple damage types
2098 if( parts->test( iteminfo_parts::GUN_ARMORPIERCE ) ) {
2099 info.push_back( iteminfo( "GUN", _( "Armor-pierce: " ), "",
2101 }
2102 if( mod->ammo_required() ) {
2103 assert( curammo ); // Appease clang-tidy
2104 int ammo_pierce = get_ranged_pierce( *curammo->ammo );
2105 // ammo_armor_pierce and sum_of_armor_pierce don't need to translate.
2107 info.push_back( iteminfo( "GUN", "ammo_armor_pierce", "",
2109 iteminfo::show_plus, ammo_pierce ) );
2110 }
2112 info.push_back( iteminfo( "GUN", "sum_of_armor_pierce", _( " = <num>" ),
2114 get_ranged_pierce( gun ) + ammo_pierce ) );
2115 }
2116 }
2117 info.back().bNewLine = true;
2118
2119 if( parts->test( iteminfo_parts::GUN_DAMAGEMULT ) ) {
2120 info.push_back( iteminfo( "GUN", _( "Damage multiplier: " ), "",
2122 gun_du.damage_multiplier ) );
2123 }
2124
2125 if( mod->ammo_required() ) {
2127 info.push_back( iteminfo( "GUN", "ammo_mult", "*",
2129 ammo_du.damage_multiplier ) );
2130 }
2131
2133 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2135 gun_du.damage_multiplier * ammo_du.damage_multiplier ) );
2136 }
2137 }
2138 info.back().bNewLine = true;
2139
2140 if( parts->test( iteminfo_parts::GUN_ARMORMULT ) ) {
2141 info.push_back( iteminfo( "GUN", _( "Armor multiplier: " ), "",
2143 gun_du.res_mult ) );
2144 }
2145 if( mod->ammo_required() ) {
2147 info.push_back( iteminfo( "GUN", "ammo_armor_mult", _( "*<num>" ),
2150 ammo_du.res_mult ) );
2151 }
2153 info.push_back( iteminfo( "GUN", "final_armor_mult", _( " = <num>" ),
2155 gun_du.res_mult * ammo_du.res_mult ) );
2156 }
2157 }
2158 info.back().bNewLine = true;
2159
2160 if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
2161 info.push_back( iteminfo( "GUN", _( "Dispersion: " ), "",
2163 mod->gun_dispersion( false, false ) ) );
2164 }
2165 if( mod->ammo_required() ) {
2166 int ammo_dispersion = curammo->ammo->dispersion;
2167 // ammo_dispersion and sum_of_dispersion don't need to translate.
2169 info.push_back( iteminfo( "GUN", "ammo_dispersion", "",
2172 ammo_dispersion ) );
2173 }
2175 info.push_back( iteminfo( "GUN", "sum_of_dispersion", _( " = <num>" ),
2177 loaded_mod->gun_dispersion( true, false ) ) );
2178 info.push_back( iteminfo( "GUN", "eff_dispersion", _( " (effective: <num>)" ),
2180 static_cast<int>( ranged::get_weapon_dispersion( you, *this ).max() ) ) );
2181 }
2182 }
2183 info.back().bNewLine = true;
2184
2185 // if effective sight dispersion differs from actual sight dispersion display both
2186 int act_disp = mod->sight_dispersion();
2187 int eff_disp = ranged::effective_dispersion( you, act_disp );
2188 int adj_disp = eff_disp - act_disp;
2189
2191 info.push_back( iteminfo( "GUN", _( "Sight dispersion: " ), "",
2193 act_disp ) );
2194
2195 if( adj_disp ) {
2196 info.push_back( iteminfo( "GUN", "sight_adj_disp", "",
2198 iteminfo::no_name | iteminfo::show_plus, adj_disp ) );
2199 info.push_back( iteminfo( "GUN", "sight_eff_disp", _( " = <num>" ),
2201 eff_disp ) );
2202 }
2203 }
2204
2205 bool bipod = mod->has_flag( flag_BIPOD );
2206
2207 if( loaded_mod->gun_recoil() ) {
2209 info.emplace_back( "GUN", _( "Recoil percentage: " ), "",
2211 std::ceil( 100 * loaded_mod->gun_recoil_multiplier() ) );
2212 }
2213 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_PERCENTAGE_BIPOD ) ) {
2214 info.emplace_back( "GUN", "bipod_recoil_percentage", _( " (with bipod <num>)" ),
2216 std::ceil( 100 * loaded_mod->gun_recoil_multiplier( true ) ) );
2217 }
2218 info.back().bNewLine = true;
2219
2220 if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
2221 info.emplace_back( "GUN", _( "Effective recoil: " ), "",
2223 loaded_mod->gun_recoil() );
2224 }
2225 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
2226 info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
2228 loaded_mod->gun_recoil( true ) );
2229 }
2230 }
2231 info.back().bNewLine = true;
2232
2233 std::map<gun_mode_id, gun_mode> fire_modes = mod->gun_all_modes();
2234 if( parts->test( iteminfo_parts::GUN_BURST_PENALTY ) ) {
2235 if( std::any_of( fire_modes.begin(), fire_modes.end(),
2236 []( const std::pair<gun_mode_id, gun_mode> &e ) {
2237 return e.second.qty > 1 && !e.second.melee();
2238 } ) ) {
2239 info.emplace_back( "GUN", _( "Burst fire penalty: " ), "",
2241 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil() ) );
2242 if( bipod ) {
2243 info.emplace_back( "GUN", "bipod_burst", _( " (with bipod <num>)" ),
2245 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil( true ) ) );
2246 }
2247 }
2248 info.back().bNewLine = true;
2249 }
2250
2251 if( parts->test( iteminfo_parts::GUN_RELOAD_TIME ) ) {
2252 info.emplace_back( "GUN", _( "Reload time: " ),
2253 has_flag( flag_RELOAD_ONE ) ? _( "<num> moves per round" ) :
2254 _( "<num> moves " ),
2255 iteminfo::lower_is_better, mod->get_reload_time() );
2256 }
2257
2258 if( parts->test( iteminfo_parts::GUN_USEDSKILL ) ) {
2259 info.push_back( iteminfo( "GUN", _( "Skill used: " ),
2260 "<info>" + skill.name() + "</info>" ) );
2261 }
2262
2263 if( mod->magazine_integral() || mod->magazine_current() ) {
2264 if( mod->magazine_current() && parts->test( iteminfo_parts::GUN_MAGAZINE ) ) {
2265 info.emplace_back( "GUN", _( "Magazine: " ),
2266 string_format( "<stat>%s</stat>",
2267 mod->magazine_current()->tname() ) );
2268 }
2269 if( mod->ammo_capacity() && parts->test( iteminfo_parts::GUN_CAPACITY ) ) {
2270 for( const ammotype &at : mod->ammo_types() ) {
2271 const std::string fmt = string_format( vgettext( "<num> round of %s",
2272 "<num> rounds of %s",
2273 mod->ammo_capacity() ), at->name() );
2274 info.emplace_back( "GUN", _( "Capacity: " ), fmt, iteminfo::no_flags,
2275 mod->ammo_capacity() );
2276 }
2277 }
2278 } else if( parts->test( iteminfo_parts::GUN_TYPE ) ) {
2279 info.emplace_back( "GUN", _( "Type: " ), enumerate_as_string( mod->ammo_types().begin(),
2280 mod->ammo_types().end(), []( const ammotype & at ) {
2281 return at->name();
2283 }
2284
2285 if( mod->ammo_data() && parts->test( iteminfo_parts::AMMO_REMAINING ) ) {
2286 info.emplace_back( "AMMO", _( "Ammunition: " ), string_format( "<stat>%s</stat>",
2287 mod->ammo_data()->nname( mod->ammo_remaining() ) ) );
2288 }
2289
2290 if( mod->get_gun_ups_drain() && parts->test( iteminfo_parts::AMMO_UPSCOST ) ) {
2291 info.emplace_back( "AMMO",
2292 string_format( vgettext( "Uses <stat>%i</stat> charge of UPS per shot",
2293 "Uses <stat>%i</stat> charges of UPS per shot",
2294 mod->get_gun_ups_drain() ),
2295 mod->get_gun_ups_drain() ) );
2296 }
2297
2298 if( parts->test( iteminfo_parts::GUN_AIMING_STATS ) ) {
2300 info.emplace_back( "GUN", _( "<bold>Base aim speed</bold>: " ), "<num>", iteminfo::no_flags,
2302 for( const ranged::aim_type &type : ranged::get_aim_types( you, *mod ) ) {
2303 // Nameless aim levels don't get an entry.
2304 if( type.name.empty() ) {
2305 continue;
2306 }
2307 // For item comparison to work correctly each info object needs a
2308 // distinct tag per aim type.
2309 const std::string tag = "GUN_" + type.name;
2310 info.emplace_back( tag, string_format( "<info>%s</info>", type.name ) );
2311 int max_dispersion = ranged::get_weapon_dispersion( you, *loaded_mod ).max();
2312 int range = range_with_even_chance_of_good_hit( max_dispersion + type.threshold );
2313 info.emplace_back( tag, _( "Even chance of good hit at range: " ),
2314 _( "<num>" ), iteminfo::no_flags, range );
2315 int aim_mv = ranged::gun_engagement_moves( you, *mod, type.threshold );
2316 info.emplace_back( tag, _( "Time to reach aim level: " ), _( "<num> moves " ),
2317 iteminfo::lower_is_better, aim_mv );
2318 }
2319 }
2320
2321 if( parts->test( iteminfo_parts::GUN_FIRE_MODES ) ) {
2322 std::vector<std::string> fm;
2323 for( const std::pair<const gun_mode_id, gun_mode> &e : fire_modes ) {
2324 if( e.second.target == this && !e.second.melee() ) {
2325 fm.emplace_back( string_format( "%s (%i)", e.second.tname(), e.second.qty ) );
2326 }
2327 }
2328 if( !fm.empty() ) {
2330 info.emplace_back( "GUN", _( "<bold>Fire modes</bold>: " ) +
2331 enumerate_as_string( fm ) );
2332 }
2333 }
2334
2337 const std::set<itype_id> compat = magazine_compatible();
2338 info.emplace_back( "DESCRIPTION", _( "<bold>Compatible magazines</bold>: " ) +
2339 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
2340 return item::nname( id );
2341 } ) );
2342 }
2343
2344 if( !gun.valid_mod_locations.empty() && parts->test( iteminfo_parts::DESCRIPTION_GUN_MODS ) ) {
2346
2347 std::string mod_str = _( "<bold>Mods</bold>: " );
2348
2349 std::map<gunmod_location, int> mod_locations = get_mod_locations();
2350
2351 int iternum = 0;
2352 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2353 if( iternum != 0 ) {
2354 mod_str += "; ";
2355 }
2356 const int free_slots = ( elem ).second - get_free_mod_locations( elem.first );
2357 mod_str += string_format( "<bold>%d/%d</bold> %s", free_slots, elem.second,
2358 elem.first.name() );
2359 bool first_mods = true;
2360 for( const item *gmod : gunmods() ) {
2361 if( gmod->type->gunmod->location == ( elem ).first ) { // if mod for this location
2362 if( first_mods ) {
2363 mod_str += ": ";
2364 first_mods = false;
2365 } else {
2366 mod_str += ", ";
2367 }
2368 mod_str += string_format( "<stat>%s</stat>", gmod->tname() );
2369 }
2370 }
2371 iternum++;
2372 }
2373 mod_str += ".";
2374 info.push_back( iteminfo( "DESCRIPTION", mod_str ) );
2375 }
2376
2377 if( mod->casings_count() && parts->test( iteminfo_parts::DESCRIPTION_GUN_CASINGS ) ) {
2379 std::string tmp = vgettext( "Contains <stat>%i</stat> casing",
2380 "Contains <stat>%i</stat> casings", mod->casings_count() );
2381 info.emplace_back( "DESCRIPTION", string_format( tmp, mod->casings_count() ) );
2382 }
2383}
@ range
Definition: character.h:104
Definition: skill.h:33
double max() const
Definition: dispersion.cpp:20
int gun_recoil(bool bipod=false) const
Get effective recoil considering handling, loaded ammo and effects of attached gunmods.
Definition: item.cpp:7326
itype_id common_ammo_default(bool conversion=true) const
Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none ...
Definition: item.cpp:7614
int get_free_mod_locations(const gunmod_location &location) const
Number of mods that can still be installed into the given mod location, for non-guns it always return...
Definition: item.cpp:4117
damage_instance gun_damage(bool with_ammo=true) const
Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
Definition: item.cpp:7277
int gun_dispersion(bool with_ammo=true, bool with_scaling=true) const
Summed dispersion of a gun, including values from mods.
Definition: item.cpp:7230
double gun_recoil_multiplier(bool bipod=false) const
Get multiplier on recoil considering handling and attached gunmods.
Definition: item.cpp:7306
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7359
bool empty() const
Whether the underlying string is empty, not matter what the context is or whether translation is need...
constexpr double MAX_RECOIL
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static const std::string flag_BIPOD("BIPOD")
@ GUN_ARMORPIERCE_LOADEDAMMO
@ GUN_RECOIL_PERCENTAGE_BIPOD
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:584
float str_draw_damage_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1032
int burst_penalty(const Character &p, const item &gun, int gun_recoil)
Definition: ranged.cpp:2163
std::vector< aim_type > get_aim_types(const Character &who, const item &gun)
Definition: ranged.cpp:1651
int effective_dispersion(const Character &who, int dispersion)
Definition: ranged.cpp:3821
dispersion_sources get_weapon_dispersion(const Character &who, const item &obj)
Get weapon's dispersion value modified accoring to character stats.
Definition: ranged.cpp:1918
double aim_per_move(const Character &who, const item &gun, double recoil)
Calculates aim improvement per move spent aiming at a given.
Definition: ranged.cpp:3920
int range_with_even_chance_of_good_hit(int dispersion)
Definition: ranged.cpp:573
float amount
Definition: damage.h:37
float res_mult
Definition: damage.h:39
std::map< gunmod_location, int > valid_mod_locations
Location for gun mods.
Definition: itype.h:521
@ no_name
Do not print the name.
Definition: item.h:148
translation name
unique string identifier for this type
Definition: itype.h:858

References _, ranged::aim_per_move(), itype::ammo, ammo_data(), ammo_default(), AMMO_REMAINING, ammo_set(), AMMO_UPSCOST, damage_unit::amount, ranged::burst_penalty(), common_ammo_default(), curammo, damage_unit::damage_multiplier, damage_instance::damage_units, debugmsg, DESCRIPTION_GUN_CASINGS, DESCRIPTION_GUN_MODS, DT_STAB, ranged::effective_dispersion(), translation::empty(), enumerate_as_string(), flag_BIPOD(), flag_RELOAD_ONE(), ranged::get_aim_types(), get_avatar(), get_free_mod_locations(), get_mod_locations(), get_ranged_pierce(), ranged::get_weapon_dispersion(), GUN_AIMING_STATS, GUN_ALLOWED_MAGAZINES, GUN_ARMORMULT, GUN_ARMORMULT_LOADEDAMMO, GUN_ARMORMULT_TOTAL, GUN_ARMORPIERCE, GUN_ARMORPIERCE_LOADEDAMMO, GUN_ARMORPIERCE_TOTAL, GUN_BURST_PENALTY, GUN_CAPACITY, gun_damage(), GUN_DAMAGE, GUN_DAMAGE_LOADEDAMMO, GUN_DAMAGE_TOTAL, GUN_DAMAGEMULT, GUN_DAMAGEMULT_AMMO, GUN_DAMAGEMULT_TOTAL, GUN_DEFAULT_AMMO, gun_dispersion(), GUN_DISPERSION, GUN_DISPERSION_LOADEDAMMO, GUN_DISPERSION_SIGHT, GUN_DISPERSION_TOTAL, ranged::gun_engagement_moves(), GUN_FIRE_MODES, GUN_MAGAZINE, GUN_MAX_RANGE, gun_range(), gun_recoil(), GUN_RECOIL, GUN_RECOIL_BIPOD, gun_recoil_multiplier(), GUN_RECOIL_PERCENTAGE, GUN_RECOIL_PERCENTAGE_BIPOD, GUN_RELOAD_TIME, GUN_TYPE, GUN_USEDSKILL, gunmods(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, iteminfo::lower_is_better, magazine_compatible(), magazine_integral(), dispersion_sources::max(), MAX_RECOIL, itype::name, Skill::name(), itype::nname(), iteminfo::no_flags, iteminfo::no_name, iteminfo::no_newline, none, range, range_with_even_chance_of_good_hit(), damage_unit::res_mult, second, iteminfo::show_plus, sign::space, ranged::str_draw_damage_modifier(), string_format(), iteminfo_query::test(), type, islot_gun::valid_mod_locations, and vgettext().

Referenced by info().

◆ gun_noise()

item::sound_data item::gun_noise ( bool  burst = false) const

Returns the sound of the gun being fired.

Parameters
burstWhether the gun was fired in burst mode (the sound string is usually different).

Definition at line 1813 of file ranged.cpp.

1814{
1815 if( !is_gun() ) {
1816 return { 0, "" };
1817 }
1818
1819 int noise = type->gun->loudness;
1820 for( const auto mod : gunmods() ) {
1821 noise += mod->type->gunmod->loudness;
1822 }
1823 if( ammo_data() ) {
1824 noise += ammo_data()->ammo->loudness;
1825 }
1826
1827 noise = std::max( noise, 0 );
1828
1830 // Grenade launchers
1831 return { 8, _( "Thunk!" ) };
1832
1833 } else if( ammo_current() == itype_12mm || ammo_current() == itype_metal_rail ) {
1834 // Railguns
1835 return { 24, _( "tz-CRACKck!" ) };
1836
1837 } else if( ammo_current() == itype_flammable || ammo_current() == itype_66mm ||
1839 // Rocket launchers and flamethrowers
1840 return { 4, _( "Fwoosh!" ) };
1841 } else if( ammo_current() == itype_arrow ) {
1842 return { noise, _( "whizz!" ) };
1843 } else if( ammo_current() == itype_bolt ) {
1844 return { noise, _( "thonk!" ) };
1845 }
1846
1847 auto fx = ammo_effects();
1848
1849 if( fx.count( ammo_effect_LASER ) || fx.count( ammo_effect_PLASMA ) ) {
1850 if( noise < 20 ) {
1851 return { noise, _( "Fzzt!" ) };
1852 } else if( noise < 40 ) {
1853 return { noise, _( "Pew!" ) };
1854 } else if( noise < 60 ) {
1855 return { noise, _( "Tsewww!" ) };
1856 } else {
1857 return { noise, _( "Kra-kow!" ) };
1858 }
1859
1860 } else if( fx.count( ammo_effect_LIGHTNING ) ) {
1861 if( noise < 20 ) {
1862 return { noise, _( "Bzzt!" ) };
1863 } else if( noise < 40 ) {
1864 return { noise, _( "Bzap!" ) };
1865 } else if( noise < 60 ) {
1866 return { noise, _( "Bzaapp!" ) };
1867 } else {
1868 return { noise, _( "Kra-koom!" ) };
1869 }
1870
1871 } else if( fx.count( ammo_effect_WHIP ) ) {
1872 return { noise, _( "Crack!" ) };
1873
1874 } else if( noise > 0 ) {
1875 if( noise < 10 ) {
1876 return { noise, burst ? _( "Brrrip!" ) : _( "plink!" ) };
1877 } else if( noise < 150 ) {
1878 return { noise, burst ? _( "Brrrap!" ) : _( "bang!" ) };
1879 } else if( noise < 175 ) {
1880 return { noise, burst ? _( "P-p-p-pow!" ) : _( "blam!" ) };
1881 } else {
1882 return { noise, burst ? _( "Kaboom!" ) : _( "kerblam!" ) };
1883 }
1884 }
1885
1886 return { 0, "" }; // silent weapons
1887}
std::set< ammo_effect_str_id > ammo_effects(bool with_ammo=true) const
Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.
Definition: item.cpp:7630
static const ammo_effect_str_id ammo_effect_WHIP("WHIP")
static const ammo_effect_str_id ammo_effect_LIGHTNING("LIGHTNING")
static const itype_id itype_12mm("12mm")
static const itype_id itype_flammable("flammable")
static const itype_id itype_m235("m235")
static const ammo_effect_str_id ammo_effect_LASER("LASER")
static const itype_id itype_40x46mm("40x46mm")
static const itype_id itype_40x53mm("40x53mm")
static const itype_id itype_bolt("bolt")
static const itype_id itype_84x246mm("84x246mm")
static const itype_id itype_metal_rail("metal_rail")
static const ammo_effect_str_id ammo_effect_PLASMA("PLASMA")
static const itype_id itype_66mm("66mm")
static const itype_id itype_arrow("arrow")

References _, itype::ammo, ammo_current(), ammo_data(), ammo_effect_LASER, ammo_effect_LIGHTNING, ammo_effect_PLASMA, ammo_effect_WHIP, ammo_effects(), itype::gun, gunmods(), is_gun(), itype_12mm, itype_40x46mm, itype_40x53mm, itype_66mm, itype_84x246mm, itype_arrow, itype_bolt, itype_flammable, itype_m235, itype_metal_rail, noise, and type.

Referenced by is_silent(), ranged::make_gun_sound_effect(), and npc::pretend_fire().

◆ gun_range() [1/2]

int item::gun_range ( bool  with_ammo = true) const

Summed range value of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7340 of file item.cpp.

7341{
7342 if( !is_gun() ) {
7343 return 0;
7344 }
7345 int ret = type->gun->range;
7346 for( const item *mod : gunmods() ) {
7347 ret += mod->type->gunmod->range;
7348 }
7349 if( with_ammo && ammo_data() ) {
7350 if( ammo_data()->ammo->shape ) {
7351 ret = ammo_data()->ammo->shape->get_range();
7352 } else {
7353 ret += ammo_data()->ammo->range;
7354 }
7355 }
7356 return std::min( std::max( 0, ret ), RANGE_HARD_CAP );
7357}
static constexpr int RANGE_HARD_CAP

References itype::ammo, ammo_data(), itype::gun, gunmods(), is_gun(), RANGE_HARD_CAP, cata::hash64_detail::ret, and type.

◆ gun_range() [2/2]

int item::gun_range ( const player p) const

The weapons range in map squares.

If the item has an active gunmod, it returns the range of that gunmod, the guns range is returned only when the item has no active gunmod. This function applies to guns and auxiliary gunmods. For other items, 0 is returned. It includes the range given by the ammo.

Parameters
pThe player that uses the weapon, their strength might affect this. It's optional and can be null.

Definition at line 7359 of file item.cpp.

7360{
7361 int ret = gun_range( true );
7362 if( p == nullptr ) {
7363 return ret;
7364 }
7365 if( !p->meets_requirements( *this ) ) {
7366 return 0;
7367 }
7368
7369 // Reduce bow range if player has less than minimum strength.
7370 ret *= ranged::str_draw_range_modifier( *this, *p );
7371
7372 return std::max( 0, ret );
7373}
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3543
float str_draw_range_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1058

References gun_range(), Character::meets_requirements(), cata::hash64_detail::ret, and ranged::str_draw_range_modifier().

Referenced by gun_info(), gun_range(), game::list_monsters(), make_gun_projectile(), turret_data::range(), and target_ui::update_ammo_range_from_gun_mode().

◆ gun_recoil()

int item::gun_recoil ( bool  bipod = false) const

Get effective recoil considering handling, loaded ammo and effects of attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
effective recoil (per shot) or zero if gun uses ammo and none is loaded

Definition at line 7326 of file item.cpp.

7327{
7328 if( !is_gun() || ( ammo_required() && !ammo_remaining() ) ) {
7329 return 0;
7330 }
7331
7332 int qty = type->gun->recoil;
7333 if( ammo_data() ) {
7334 qty += ammo_data()->ammo->recoil;
7335 }
7336
7337 return qty * gun_recoil_multiplier( bipod );
7338}

References itype::ammo, ammo_data(), ammo_remaining(), ammo_required(), itype::gun, gun_recoil_multiplier(), is_gun(), and type.

Referenced by calculate_dispersion(), npc::confident_gun_mode_range(), ranged::fire_gun(), and gun_info().

◆ gun_recoil_multiplier()

double item::gun_recoil_multiplier ( bool  bipod = false) const

Get multiplier on recoil considering handling and attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
multiplier on recoil applied to shots fired from this gun

Definition at line 7306 of file item.cpp.

7307{
7308 double handling = type->gun->handling;
7309 for( const item *mod : gunmods() ) {
7310 if( bipod || !mod->has_flag( flag_BIPOD ) ) {
7311 handling += mod->type->gunmod->handling;
7312 }
7313 }
7314
7315 // Rescale from JSON units which are intentionally specified as integral values
7316 handling /= 10;
7317
7318 // Handling will almost always be above 1.0
7319 if( handling > 1.0 ) {
7320 return 1.0 / handling;
7321 } else {
7322 return 2.0 - handling;
7323 }
7324}

References flag_BIPOD(), itype::gun, gunmods(), and type.

Referenced by gun_info(), and gun_recoil().

◆ gun_set_mode()

bool item::gun_set_mode ( const gun_mode_id mode)

Try to set the mode for a gun, returning false if no such mode is possible.

Definition at line 7912 of file item.cpp.

7913{
7914 if( !is_gun() || is_gunmod() || !gun_all_modes().count( mode ) ) {
7915 return false;
7916 }
7917 set_var( GUN_MODE_VAR_NAME, mode.str() );
7918 return true;
7919}

References count(), gun_all_modes(), GUN_MODE_VAR_NAME(), is_gun(), is_gunmod(), set_var(), and string_id< T >::str().

Referenced by target_ui::action_switch_mode(), gun_cycle_mode(), avatar_funcs::gunmod_remove(), game::handle_action(), io(), and gun_actor::shoot().

◆ gun_skill()

skill_id item::gun_skill ( ) const

◆ gunmod_find() [1/2]

item * item::gunmod_find ( const itype_id mod)

Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.

Definition at line 7747 of file item.cpp.

7748{
7749 std::vector<item *> mods = gunmods();
7750 auto it = std::find_if( mods.begin(), mods.end(), [&mod]( item * e ) {
7751 return e->typeId() == mod;
7752 } );
7753 return it != mods.end() ? *it : nullptr;
7754}

References gunmods().

Referenced by saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), cycle_action(), gunmod_find(), is_gunmod_compatible(), tname(), volume(), and weight().

◆ gunmod_find() [2/2]

const item * item::gunmod_find ( const itype_id mod) const

Definition at line 7756 of file item.cpp.

7757{
7758 return const_cast<item *>( this )->gunmod_find( mod );
7759}
item * gunmod_find(const itype_id &mod)
Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.
Definition: item.cpp:7747

References gunmod_find().

◆ gunmod_info()

void item::gunmod_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2385 of file item.cpp.

2387{
2388 if( !is_gunmod() ) {
2389 return;
2390 }
2391 const islot_gunmod &mod = *type->gunmod;
2392
2393 if( is_gun() && parts->test( iteminfo_parts::DESCRIPTION_GUNMOD ) ) {
2394 info.push_back( iteminfo( "DESCRIPTION",
2395 _( "This mod <info>must be attached to a gun</info>, "
2396 "it can not be fired separately." ) ) );
2397 }
2399 info.push_back( iteminfo( "DESCRIPTION",
2400 _( "When attached to a gun, <good>allows</good> making "
2401 "<info>reach melee attacks</info> with it." ) ) );
2402 }
2403 if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
2404 info.push_back( iteminfo( "GUNMOD", _( "Dispersion modifier: " ), "",
2406 mod.dispersion ) );
2407 }
2408 if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
2409 info.push_back( iteminfo( "GUNMOD", _( "Sight dispersion: " ), "",
2410 iteminfo::lower_is_better, mod.sight_dispersion ) );
2411 }
2412 if( mod.aim_speed >= 0 && parts->test( iteminfo_parts::GUNMOD_AIMSPEED ) ) {
2413 info.push_back( iteminfo( "GUNMOD", _( "Aim speed: " ), "",
2414 iteminfo::lower_is_better, mod.aim_speed ) );
2415 }
2416 int total_damage = static_cast<int>( mod.damage.total_damage() );
2417 if( total_damage != 0 && parts->test( iteminfo_parts::GUNMOD_DAMAGE ) ) {
2418 info.push_back( iteminfo( "GUNMOD", _( "Damage: " ), "", iteminfo::show_plus,
2419 total_damage ) );
2420 }
2421 int pierce = get_ranged_pierce( mod );
2423 info.push_back( iteminfo( "GUNMOD", _( "Armor-pierce: " ), "", iteminfo::show_plus,
2424 pierce ) );
2425 }
2426 if( mod.handling != 0 && parts->test( iteminfo_parts::GUNMOD_HANDLING ) ) {
2427 info.emplace_back( "GUNMOD", _( "Handling modifier: " ), "",
2428 iteminfo::show_plus, mod.handling );
2429 }
2430 if( !type->mod->ammo_modifier.empty() && parts->test( iteminfo_parts::GUNMOD_AMMO ) ) {
2431 for( const ammotype &at : type->mod->ammo_modifier ) {
2432 info.push_back( iteminfo( "GUNMOD", string_format( _( "Ammo: <stat>%s</stat>" ),
2433 at->name() ) ) );
2434 }
2435 }
2436 if( mod.reload_modifier != 0 && parts->test( iteminfo_parts::GUNMOD_RELOAD ) ) {
2437 info.emplace_back( "GUNMOD", _( "Reload modifier: " ), _( "<num>%" ),
2438 iteminfo::lower_is_better, mod.reload_modifier );
2439 }
2440 if( mod.min_str_required_mod > 0 && parts->test( iteminfo_parts::GUNMOD_STRENGTH ) ) {
2441 info.push_back( iteminfo( "GUNMOD", _( "Minimum strength required modifier: " ),
2442 mod.min_str_required_mod ) );
2443 }
2444 if( !mod.add_mod.empty() && parts->test( iteminfo_parts::GUNMOD_ADD_MOD ) ) {
2446
2447 std::string mod_loc_str = _( "<bold>Adds mod locations: </bold> " );
2448
2449 std::map<gunmod_location, int> mod_locations = mod.add_mod;
2450
2451 int iternum = 0;
2452 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2453 if( iternum != 0 ) {
2454 mod_loc_str += "; ";
2455 }
2456 mod_loc_str += string_format( "<bold>%s</bold> %s", elem.second, elem.first.name() );
2457 iternum++;
2458 }
2459 mod_loc_str += ".";
2460 info.push_back( iteminfo( "GUNMOD", mod_loc_str ) );
2461 }
2462
2464
2465 if( parts->test( iteminfo_parts::GUNMOD_USEDON ) ) {
2466 std::string used_on_str = _( "<bold>Used on:</bold>" );
2467
2468 if( !mod.usable.empty() ) {
2469 used_on_str += _( "\n Specific: " ) + enumerate_as_string( mod.usable.begin(),
2470 mod.usable.end(), []( const itype_id & used_on ) {
2471 return string_format( "<info>%s</info>", used_on->nname( 1 ) );
2472 } );
2473 }
2474
2475 if( !mod.usable_category.empty() ) {
2476 used_on_str += _( "\n Category: " );
2477 std::vector<std::string> combination;
2478 for( const std::unordered_set<weapon_category_id> &catgroup : mod.usable_category ) {
2479 combination.emplace_back( ( "[" ) + enumerate_as_string( catgroup.begin(),
2480 catgroup.end(), []( const weapon_category_id & wcid ) {
2481 return string_format( "<info>%s</info>", wcid->name().translated() );
2482 }, enumeration_conjunction::none ) + ( "]" ) );
2483 }
2484 used_on_str += enumerate_as_string( combination, enumeration_conjunction::or_ );
2485 }
2486
2487 info.push_back( iteminfo( "GUNMOD", used_on_str ) );
2488 }
2489
2490 if( parts->test( iteminfo_parts::GUNMOD_LOCATION ) ) {
2491 info.push_back( iteminfo( "GUNMOD", string_format( _( "Location: %s" ),
2492 mod.location.name() ) ) );
2493 }
2494
2495 if( !mod.blacklist_mod.empty() && parts->test( iteminfo_parts::GUNMOD_BLACKLIST_MOD ) ) {
2496 std::string mod_black_str = _( "<bold>Incompatible with mod location: </bold> " );
2497
2498 int iternum = 0;
2499 for( const gunmod_location &black : mod.blacklist_mod ) {
2500 if( iternum != 0 ) {
2501 mod_black_str += ", ";
2502 }
2503 mod_black_str += string_format( "%s", black.name() );
2504 iternum++;
2505 }
2506 mod_black_str += ".";
2507 info.push_back( iteminfo( "GUNMOD", mod_black_str ) );
2508 }
2509}
cata::value_ptr< islot_gunmod > gunmod
Definition: itype.h:831
cata::value_ptr< islot_mod > mod
Definition: itype.h:826

References _, catacurses::black, DESCRIPTION_GUNMOD, DESCRIPTION_GUNMOD_REACH, enumerate_as_string(), flag_REACH_ATTACK(), get_ranged_pierce(), itype::gunmod, GUNMOD_ADD_MOD, GUNMOD_AIMSPEED, GUNMOD_AMMO, GUNMOD_ARMORPIERCE, GUNMOD_BLACKLIST_MOD, GUNMOD_DAMAGE, GUNMOD_DISPERSION, GUNMOD_DISPERSION_SIGHT, GUNMOD_HANDLING, GUNMOD_LOCATION, GUNMOD_RELOAD, GUNMOD_STRENGTH, GUNMOD_USEDON, has_flag(), info(), insert_separation_line(), is_gun(), is_gunmod(), iteminfo::lower_is_better, itype::mod, ammunition_type::name(), none, or_, iteminfo::show_plus, string_format(), iteminfo_query::test(), and type.

Referenced by info().

◆ gunmods() [1/2]

◆ gunmods() [2/2]

std::vector< const item * > item::gunmods ( ) const

Definition at line 7742 of file item.cpp.

7743{
7744 return contents.gunmods();
7745}

References contents, and item_contents::gunmods().

◆ handle_craft_failure()

bool item::handle_craft_failure ( player crafter)

Handle failure during crafting.

Destroy components, lose progress, and set a new failure point.

Parameters
crafterthe crafting player.
Returns
whether the craft being worked on should be entirely destroyed

Definition at line 931 of file crafting.cpp.

932{
933 if( !is_craft() ) {
934 debugmsg( "handle_craft_failure() called on non-craft '%s.' Aborting.", tname() );
935 return false;
936 }
937
938 const double success_roll = crafter.crafting_success_roll( get_making() );
939 const int starting_components = this->components.size();
940 // Destroy at most 75% of the components, always a chance of losing 1 though
941 const size_t max_destroyed = std::max<size_t>( 1, components.size() * 3 / 4 );
942 for( size_t i = 0; i < max_destroyed; i++ ) {
943 // This shouldn't happen
944 if( components.empty() ) {
945 break;
946 }
947 // If we roll success, skip destroying a component
948 if( x_in_y( success_roll, 1.0 ) ) {
949 continue;
950 }
951 destroy_random_component( *this, crafter );
952 }
953 if( starting_components > 0 && this->components.empty() ) {
954 // The craft had components and all of them were destroyed.
955 return true;
956 }
957
958 // Minimum 25% progress lost, average 35%. Falls off exponentially
959 // Loss is scaled by the success roll
960 const double percent_progress_loss = rng_exponential( 0.25, 0.35 ) *
961 ( 1.0 - std::min( success_roll, 1.0 ) );
962 const int progess_loss = item_counter * percent_progress_loss;
963 crafter.add_msg_player_or_npc( _( "You mess up and lose %d%% progress." ),
964 _( "<npcname> messes up and loses %d%% progress." ), progess_loss / 100000 );
965 item_counter = clamp( item_counter - progess_loss, 0, 10000000 );
966
967 set_next_failure_point( crafter );
968
969 // Check if we can consume a new component and continue
970 if( !crafter.can_continue_craft( *this ) ) {
971 crafter.cancel_activity();
972 }
973 return false;
974}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
void cancel_activity()
Definition: character.cpp:9239
const recipe & get_making() const
Get the stored recipe for in progress crafts.
Definition: item.cpp:10096
void set_next_failure_point(const player &crafter)
Calculates and sets the next failure point for an in progress craft.
Definition: crafting.cpp:905
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:372
bool can_continue_craft(item &craft)
Check if the player meets the requirements to continue the in progress craft and if unable to continu...
Definition: crafting.cpp:1169
double crafting_success_roll(const recipe &making) const
Calculate a value representing the success of the player at crafting the given recipe,...
Definition: crafting.cpp:821
static void destroy_random_component(item &craft, const player &crafter)
Definition: crafting.cpp:918
double rng_exponential(double min, double mean)
Definition: rng.cpp:55

References _, player::add_msg_player_or_npc(), player::can_continue_craft(), Character::cancel_activity(), clamp(), components, player::crafting_success_roll(), debugmsg, destroy_random_component(), get_making(), is_craft(), item_counter, rng_exponential(), set_next_failure_point(), tname(), and x_in_y().

◆ handle_pickup_ownership()

void item::handle_pickup_ownership ( Character c)

Definition at line 4498 of file item.cpp.

4499{
4500 if( is_owned_by( c ) ) {
4501 return;
4502 }
4503 // Add ownership to item if unowned
4504 if( owner.is_null() ) {
4505 set_owner( c );
4506 } else {
4508 if( !is_owned_by( c ) && &c == &you ) {
4509 std::vector<npc *> witnesses;
4510 for( npc &elem : g->all_npcs() ) {
4511 if( rl_dist( elem.pos(), you.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
4512 is_owned_by( elem ) && elem.sees( you.pos() ) ) {
4513 elem.say( "<witnessed_thievery>", 7 );
4514 npc *npc_to_add = &elem;
4515 witnesses.push_back( npc_to_add );
4516 }
4517 }
4518 if( !witnesses.empty() ) {
4520 // Make sure there is only one witness
4521 for( npc &guy : g->all_npcs() ) {
4522 if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
4523 guy.set_attitude( NPCATT_NULL );
4524 }
4525 }
4526 random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
4527 // Notify the activity that we got a witness
4528 if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
4529 c.activity.str_values.clear();
4530 c.activity.str_values.emplace_back( has_thievery_witness );
4531 }
4532 }
4533 set_owner( c );
4534 }
4535 }
4536}
const tripoint & pos() const override
Definition: character.cpp:601
bool is_owned_by(const Character &c, bool available_to_take=false) const
Definition: item.cpp:1239
void set_old_owner(const faction_id &temp_owner)
Definition: item.h:2029
void set_owner(const faction_id &new_owner)
Definition: item.h:2035
Definition: npc.h:744
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int MAX_VIEW_DISTANCE
static const activity_id ACT_PICKUP("ACT_PICKUP")
static const std::string has_thievery_witness("has_thievery_witness")
@ NPCATT_NULL
Definition: npc.h:81
@ NPCATT_RECOVER_GOODS
Definition: npc.h:100

References ACT_PICKUP, c, g, get_owner(), get_player_character(), has_thievery_witness(), string_id< T >::is_null(), is_owned_by(), MAX_VIEW_DISTANCE, NPCATT_NULL, NPCATT_RECOVER_GOODS, owner, Character::pos(), random_entry(), rl_dist(), set_old_owner(), and set_owner().

Referenced by on_pickup(), on_wear(), and on_wield().

◆ has_any_flag()

template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool item::has_any_flag ( const Container &  flags) const
inline

Definition at line 1417 of file item.h.

1417 {
1418 return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1419 return has_flag( flag );
1420 } );
1421 }

Referenced by Character::can_eat(), and Character::consume_effects().

◆ has_clothing_mod()

bool item::has_clothing_mod ( ) const

Definition at line 10140 of file item.cpp.

10141{
10142 for( const clothing_mod &cm : clothing_mods::get_all() ) {
10143 if( has_own_flag( cm.flag ) ) {
10144 return true;
10145 }
10146 }
10147 return false;
10148}
const std::vector< clothing_mod > & get_all()

References clothing_mods::get_all(), and has_own_flag().

Referenced by tname().

◆ has_effect_when_carried()

bool item::has_effect_when_carried ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is carried?

Definition at line 9764 of file item.cpp.

9765{
9766 if( !type->artifact ) {
9767 return false;
9768 }
9769 const std::vector<art_effect_passive> &ec = type->artifact->effects_carried;
9770 if( std::find( ec.begin(), ec.end(), effect ) != ec.end() ) {
9771 return true;
9772 }
9773 for( const item *i : contents.all_items_top() ) {
9774 if( i->has_effect_when_carried( effect ) ) {
9775 return true;
9776 }
9777 }
9778 return false;
9779}
Definition: effect.h:164
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:837

References item_contents::all_items_top(), itype::artifact, contents, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_wielded()

bool item::has_effect_when_wielded ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is wielded?

Definition at line 9746 of file item.cpp.

9747{
9748 if( !type->artifact ) {
9749 return false;
9750 }
9751 const std::vector<art_effect_passive> &ew = type->artifact->effects_wielded;
9752 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9753}

References itype::artifact, detail::find(), and type.

Referenced by Character::hardcoded_effects().

◆ has_effect_when_worn()

bool item::has_effect_when_worn ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is worn?

Definition at line 9755 of file item.cpp.

9756{
9757 if( !type->artifact ) {
9758 return false;
9759 }
9760 const std::vector<art_effect_passive> &ew = type->artifact->effects_worn;
9761 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9762}

References itype::artifact, detail::find(), and type.

◆ has_explosion_data()

bool item::has_explosion_data ( ) const

Definition at line 6836 of file item.cpp.

6837{
6838 return is_fuel() ? type->fuel->has_explode_data : false;
6839}

References itype::fuel, is_fuel(), and type.

Referenced by vehicle::explode_fuel().

◆ has_fault()

bool item::has_fault ( const fault_id fault) const

Does this item have the specified fault.

Definition at line 5320 of file item.cpp.

5321{
5322 return faults.count( fault );
5323}
Definition: fault.h:29

References faults.

Referenced by install_bionic_actor::can_use(), color_in_inventory(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), ranged::handle_gun_damage(), bionic_sterilize_preset::is_shown(), and tname().

◆ has_flag() [1/2]

bool item::has_flag ( const flag_str_id flag) const

Definition at line 5354 of file item.cpp.

5355{
5356 return has_flag( flag.str() );
5357}

References has_flag(), and string_id< T >::str().

◆ has_flag() [2/2]

bool item::has_flag ( const std::string &  flag) const

Definition at line 5330 of file item.cpp.

5331{
5332 bool ret = false;
5333
5334 if( json_flag::get( f ).inherit() ) {
5335 for( const item *e : is_gun() ? gunmods() : toolmods() ) {
5336 // gunmods fired separately do not contribute to base gun flags
5337 if( !e->is_gun() && e->has_flag( f ) ) {
5338 return true;
5339 }
5340 }
5341 }
5342
5343 // other item type flags
5344 ret = type->has_flag( f );
5345 if( ret ) {
5346 return ret;
5347 }
5348
5349 // now check for item specific flags
5350 ret = has_own_flag( f );
5351 return ret;
5352}
bool has_flag(const std::string &flag) const
Definition: itype.cpp:146

References json_flag::get(), gunmods(), itype::has_flag(), has_own_flag(), is_gun(), cata::hash64_detail::ret, toolmods(), and type.

Referenced by Character::activate_bionic(), map::add_item(), map::add_item_or_charges(), monexamine::add_leash(), Character::all_items_with_flag(), Character::allergy_type(), npc::alt_attack(), ammo_consume(), ammo_remaining(), ammo_required(), ammo_set(), amount_of_internal(), Character::armor_absorb(), armor_fit_info(), armor_info(), iexamine::autodoc(), autodoc_internal(), basic_info(), mattack::bio_op_disarm(), iuse::blech(), Character::block_hit(), blocking_ability(), Character::burn_fuel(), butcher_time_to_cut(), butchery_drops_harvest(), iuse::camera(), item_funcs::can_be_unloaded(), Character::can_consume(), can_do_activity_there(), Character::can_eat(), Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), repair_item_actor::can_repair_target(), can_revive(), Character::can_swap(), Character::can_takeoff(), Character::can_unwield(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), cast_spell(), check_litcig(), anonymous_namespace{armor_layers.cpp}::clothing_flags_description(), anonymous_namespace{armor_layers.cpp}::clothing_layer(), color_in_inventory(), combat_info(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), Character::compute_effective_nutrients(), Character::compute_nutrient_range(), conductive(), consider_butchery(), Character::consume_charges(), game_menus::inv::consume_drink(), Character::consume_effects(), game_menus::inv::consume_food(), Character::consume_med(), Character::consume_remote_fuel(), vehicle::consumption_per_hour(), corpse_volume(), activity_handlers::cracking_do_turn(), recipe::create_byproducts(), Single_item_creator::create_single(), iexamine::cvdmachine(), cycle_action(), damage_melee(), repair_item_actor::default_action(), iexamine::dimensional_portal(), display_name(), aim_activity_actor::do_turn(), draw_bionics_titlebar(), game::dump_stats(), durability_indicator(), Character::eat(), einkpc_download_memory_card(), iuse::einktabletpc(), emit_radio_signal(), final_info(), character_funcs::find_ammo_helper(), find_auto_consume(), find_food_heater(), Character::find_remote_fuel(), findBestGasDiscount(), ranged::fire_gun(), activity_handlers::fish_do_turn(), character_funcs::fmt_wielded_weapon(), food_info(), inventory::form_from_map(), Character::fun_for(), activity_handlers::game_do_turn(), character_funcs::get_book_fun_for(), activatable_inventory_preset::get_denial(), bionic_sterilize_preset::get_denial(), get_encumber_when_containing(), ranged::get_fastest_sight(), Character::get_fuel_available(), get_layer(), zone_manager::get_near_zone_type_for_item(), get_sizing(), ranged::get_str_draw_penalty(), getlight_emit(), give_item_to(), goes_bad(), gun_info(), iuse::gun_repair(), gunmod_info(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), ranged::handle_gun_damage(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), has_flag(), Character::has_item_with_flag(), Character::head_cloth_encumbrance(), iuse_transform::info(), inherit_flags(), npc_trading::init_buying(), init_memory_card_with_random_stuff(), target_ui::init_window_and_input(), monexamine::insert_battery(), is_ammo_belt(), is_armor(), is_corpse(), is_dangerous(), advanced_inventory_pane::is_filtered(), is_filthy(), is_firearm(), character_funcs::is_fun_to_read(), is_gunmod_compatible(), is_irremovable(), vehicle::is_perpetual_type(), is_pet_armor(), is_power_armor(), is_reloadable(), is_salvageable(), bionic_uninstall_preset::is_shown(), is_two_handed(), is_unarmed_weapon(), ma_requirements::is_valid_character(), ma_requirements::is_valid_weapon(), is_worn_only_with(), item(), Character::item_reload_cost(), mdeath::jabberwock(), layer_item(), magazine_info(), item_action_generator::map_actions_to_items(), Character::meets_stat_requirements(), Character::melee_attack(), melee_skill(), Character::melee_special_effects(), npc_ai::melee_value(), mine_activity(), Item_modifier::modify(), Character::modify_morale(), avatar_action::move(), game_menus::inv::multiwash(), Character::mutation_effect(), iexamine::nanofab(), needs_processing(), iuse::note_bionics(), on_wear(), on_wield(), iuse::pack_cbm(), Character::passive_power_gen(), monexamine::pet_menu(), avatar_action::plthrow(), iuse::poison(), item_category::priority_zone(), process_extinguish(), process_internal(), Character::process_items(), process_litcig(), process_tool(), process_UPS(), process_vehicle_items(), vehicle_part::properties_to_item(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), iuse::radiocontrol(), rate_food(), rcdrive(), reach_range(), ready_to_revive(), reinforceable(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), remove_ammo(), remove_radio_mod(), repair_item_actor::repair(), repaired_with(), game::revive_corpse(), iexamine::safe(), character_funcs::select_ammo(), set_relative_rot(), player_morale::set_worn(), sight_dispersion(), iexamine::sign(), smoker_load_food(), map::spawn_item(), activity_handlers::spellcasting_finish(), activity_handlers::start_fire_do_turn(), starting_clothes(), starting_inv(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), ranged::str_draw_range_modifier(), ranged::throw_item(), tname(), tool_info(), iuse::toolmod_attach(), iuse::towel_common(), type_name(), Character::unarmed_attack(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse_transform::use(), set_transform_iuse::use(), unpack_actor::use(), cast_spell_actor::use(), Character::use_charges(), iexamine::use_furn_fake_item(), avatar_action::use_item(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), volume(), martialart::weapon_valid(), npc::wear_if_wanted(), Character::wear_item(), iuse::weather_tool(), weight(), weather_effect::wet_player(), npc::will_accept_from_player(), and Character::will_eat().

◆ has_infinite_charges()

bool item::has_infinite_charges ( ) const

Definition at line 9968 of file item.cpp.

9969{
9970 return charges == INFINITE_CHARGES;
9971}

References charges, and INFINITE_CHARGES.

Referenced by display_name(), liquid_handler::get_liquid_target(), mod_charges(), and Character::will_eat().

◆ has_label()

bool item::has_label ( ) const

Returns true if item has "item_label" itemvar.

Definition at line 9954 of file item.cpp.

9955{
9956 return has_var( "item_label" );
9957}

References has_var().

Referenced by label().

◆ has_own_flag()

bool item::has_own_flag ( const std::string &  flag) const

Checks whether item itself has given flag (doesn't check item type or gunmods).

Essentially get_flags().count(f). Works faster than has_flag

Definition at line 5325 of file item.cpp.

5326{
5327 return item_tags.count( f );
5328}
size_type count(const T &t) const
Definition: flat_set.h:141

References cata::flat_set< T, Compare, Data >::count(), and item_tags.

Referenced by Character::can_eat(), Character::can_wear(), color_in_inventory(), final_info(), has_clothing_mod(), has_flag(), mod_last_rot_check(), on_drop(), tname(), update_clothing_mod_val(), and sew_advanced_actor::use().

◆ has_property()

bool item::has_property ( const std::string &  prop) const

Definition at line 5385 of file item.cpp.

5386{
5387 return type->properties.find( prop ) != type->properties.end();
5388}

References itype::properties, and type.

Referenced by iuse::capture_monster_act(), and ranged::throw_item().

◆ has_rotten_away()

bool item::has_rotten_away ( ) const

Whether the item has enough rot that it should get removed.

Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days

Returns
true if the item has enough rot to be removed, false otherwise.

Definition at line 8796 of file item.cpp.

8797{
8798 if( is_corpse() && !can_revive() ) {
8799 return get_rot() > 10_days;
8800 } else {
8801 return is_food() && get_relative_rot() > 2.0;
8802 }
8803}
time_duration get_rot() const
Definition: item.h:860

References can_revive(), get_relative_rot(), get_rot(), is_corpse(), and is_food().

Referenced by process_rot().

◆ has_technique()

bool item::has_technique ( const matec_id tech) const

Whether the item supports a specific martial art technique (either through its type, or through its individual techniques).

Definition at line 5466 of file item.cpp.

5467{
5468 return type->techniques.count( tech ) > 0 || techniques.count( tech ) > 0;
5469}

References techniques, itype::techniques, and type.

Referenced by blocking_ability(), effective_dps(), character_martial_arts::has_technique(), and mdeath::jabberwock().

◆ has_tools_to_continue()

bool item::has_tools_to_continue ( ) const

Definition at line 10113 of file item.cpp.

10114{
10115 assert( craft_data_ );
10116 return craft_data_->tools_to_continue;
10117}

References craft_data_.

◆ has_use()

bool item::has_use ( ) const

Returns true if the item has any use function.

Definition at line 7944 of file item.cpp.

7945{
7946 return type->has_use();
7947}
bool has_use() const
Definition: itype.cpp:141

References itype::has_use(), and type.

Referenced by find_auto_consume().

◆ has_var()

◆ ideal_ranged_dps()

double item::ideal_ranged_dps ( const Character who,
gun_mode mode 
) const

Definition at line 2080 of file npcmove.cpp.

2081{
2082 if( !is_gun() ) {
2083 return 0;
2084 }
2086 if( ammo_current() ) {
2087 itype_id ammo = ammo_current();
2088 gun_damage.add( ammo->ammo->damage );
2089 } else if( ammo_default() ) {
2090 itype_id ammo = ammo_default();
2091 gun_damage.add( ammo->ammo->damage );
2092 }
2093 float damage_factor = gun_damage.total_damage();
2094 damage_factor *= mode.qty;
2095
2096 int move_cost = ranged::time_to_attack( who, *this, item_location() );
2097 if( ammo_remaining() == 0 ) {
2098 int reload_cost = get_reload_time() + who.encumb( bp_hand_l ) + who.encumb( bp_hand_r );
2099 // HACK: Doesn't check how much ammo they'll actually get from the reload. Because we don't know.
2100 // DPS is less impacted the larger the magazine being swapped.
2101 reload_cost /= magazine_integral() ? 1 : ammo_capacity() / mode.qty;
2102 move_cost += reload_cost;
2103 }
2104 std::vector<ranged::aim_type> aim_types = ranged::get_aim_types( who, *this );
2105 auto regular = std::find_if( aim_types.begin(),
2106 aim_types.end(), []( ranged::aim_type at ) {
2107 return at.action == std::string( "AIMED_SHOT" );
2108 } );
2109 if( regular == aim_types.end() ) {
2110 debugmsg( "Could not find REGULAR aim type for gun %s", tname() );
2111 return 0;
2112 }
2113 move_cost += ranged::gun_engagement_moves( who, *this, ( *regular ).threshold );
2114
2115 double dps = damage_factor / ( move_cost / 100.0f );
2116
2117 return dps;
2118}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int qty
burst size for is_gun() firearms, or melee range for is_melee() weapons
Definition: gun_mode.h:21
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
int get_reload_time() const
Returns the reload time of the gun.
Definition: item.cpp:6538
void regular(const queued_explosion &qe)
Definition: explosion.cpp:1467
int time_to_attack(const Character &p, const item &firing, const item_location loc)
Calculates time taken to fire gun.
Definition: ranged.cpp:1735
void add(const damage_instance &added_di)
Definition: damage.cpp:93

References damage_instance::add(), itype::ammo, ammo_capacity(), ammo_current(), ammo_default(), ammo_remaining(), bp_hand_l, bp_hand_r, debugmsg, dps(), Character::encumb(), ranged::get_aim_types(), get_reload_time(), gun_damage(), ranged::gun_engagement_moves(), is_gun(), magazine_integral(), move_cost(), gun_mode::qty, explosion_handler::explosion_funcs::regular(), ranged::time_to_attack(), tname(), and damage_instance::total_damage().

Referenced by npc::check_or_use_weapon_cbm(), and npc_ai::gun_value().

◆ in_container()

item item::in_container ( const itype_id container_type) const

Definition at line 851 of file item.cpp.

852{
853 if( !cont.is_null() ) {
854 item ret( cont, birthday() );
855 ret.put_in( *this );
856 if( made_of( LIQUID ) && ret.is_container() ) {
857 // Note: we can't use any of the normal container functions as they check the
858 // container being suitable (seals, watertight etc.)
859 ret.contents.back().charges = charges_per_volume( ret.get_container_capacity() );
860 }
861
862 ret.invlet = invlet;
863 return ret;
864 } else {
865 return *this;
866 }
867}
char invlet
Definition: item.h:2246

References birthday(), charges_per_volume(), invlet, string_id< T >::is_null(), LIQUID, made_of(), and cata::hash64_detail::ret.

Referenced by in_its_container().

◆ in_its_container()

item item::in_its_container ( ) const

Returns this item into its default container.

If it does not have a default container, returns this. It's intended to be used like

newitem = newitem.in_its_container();

Definition at line 846 of file item.cpp.

847{
848 return in_container( type->default_container.value_or( itype_id::NULL_ID() ) );
849}
item in_container(const itype_id &container_type) const
Definition: item.cpp:851
std::optional< itype_id > default_container
Definition: itype.h:883

References itype::default_container, in_container(), string_id< itype >::NULL_ID(), and type.

Referenced by defense_game::caravan(), crafting::complete_disassemble(), Single_item_creator::create_single(), map::spawn_an_item(), starting_inv(), and debug_menu::wishitem().

◆ inc_damage() [1/2]

bool item::inc_damage ( )

same as other inc_damage, but uses DT_NULL as damage type.

Definition at line 6268 of file item.cpp.

6269{
6270 return inc_damage( DT_NULL );
6271}
bool inc_damage()
same as other inc_damage, but uses DT_NULL as damage type.
Definition: item.cpp:6268

References DT_NULL, and inc_damage().

Referenced by inc_damage(), and process_blackpowder_fouling().

◆ inc_damage() [2/2]

bool item::inc_damage ( damage_type  dt)

Increment item damage by itype::damage_scale constrained by max_damage.

Parameters
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6263 of file item.cpp.

6264{
6265 return mod_damage( itype::damage_scale, dt );
6266}
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6236
static constexpr int damage_scale
Definition: itype.h:979

References itype::damage_scale, and mod_damage().

Referenced by iuse::blood_draw(), damage_item(), iuse::firecracker_pack_act(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), Character::handle_melee_wear(), activity_handlers::lockpicking_finish(), and vehicle::operate_scoop().

◆ info() [1/4]

std::vector< iteminfo > item::info ( ) const

Return all the information about the item and its type as a vector.

This includes the different properties of the itype (if they are visible to the player).

Parameters
partscontrols which parts of the iteminfo to return.
batchThe batch crafting number to multiply data by
Returns
The properties (encapsulated into iteminfo) are added to this vector, the vector can be used to compare them to properties of another item.

Definition at line 3993 of file item.cpp.

3994{
3996}
static const iteminfo_query no_conditions

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

Referenced by advanced_inventory::action_examine(), ammo_info(), animal_armor_info(), armor_fit_info(), armor_info(), armor_protection_info(), basic_info(), battery_info(), bionic_info(), book_info(), combat_info(), game_menus::inv::compare(), component_info(), container_info(), contents_info(), disassembly_info(), final_info(), food_info(), gun_info(), gunmod_info(), info(), info_string(), game::list_items(), magazine_info(), med_info(), qualities_info(), wish_item_callback::refresh(), repair_info(), examine_item_menu::run(), trading_window::show_item_data(), and tool_info().

◆ info() [2/4]

std::vector< iteminfo > item::info ( const iteminfo_query parts,
int  batch,
temperature_flag  temperature 
) const

Definition at line 4008 of file item.cpp.

4010{
4011 const bool debug = g != nullptr && debug_mode;
4012
4013 // TODO: Use reference properly
4014 const iteminfo_query *parts = &parts_ref;
4015 std::vector<iteminfo> info;
4016
4017 if( !is_null() ) {
4018 basic_info( info, parts, batch, debug );
4019 }
4020
4021 const item *med_item = nullptr;
4022 if( is_medication() ) {
4023 med_item = this;
4024 } else if( is_med_container() ) {
4025 med_item = &contents.front();
4026 }
4027 if( med_item != nullptr ) {
4028 med_info( med_item, info, parts, batch, debug );
4029 }
4030
4031 if( const item *food_item = get_food() ) {
4032 food_info( food_item, info, parts, batch, debug, temperature );
4033 }
4034
4035 container_info( info, parts, batch, debug );
4036 contents_info( info, parts, batch, debug );
4037 combat_info( info, parts, batch, debug );
4038
4039 magazine_info( info, parts, batch, debug );
4040 ammo_info( info, parts, batch, debug );
4041
4042 const item *gun = nullptr;
4043 if( is_gun() ) {
4044 gun = this;
4045 const gun_mode aux = gun_current_mode();
4046 // if we have an active auxiliary gunmod display stats for this instead
4047 if( aux && aux->is_gunmod() && aux->is_gun() &&
4049 gun = &*aux;
4050 info.emplace_back( "DESCRIPTION",
4051 string_format( _( "Stats of the active <info>gunmod (%s)</info> "
4052 "are shown." ), gun->tname() ) );
4053 }
4054 }
4055 if( gun != nullptr ) {
4056 gun_info( gun, info, parts, batch, debug );
4057 }
4058
4059 gunmod_info( info, parts, batch, debug );
4060 armor_info( info, parts, batch, debug );
4061 animal_armor_info( info, parts, batch, debug );
4062 book_info( info, parts, batch, debug );
4063 battery_info( info, parts, batch, debug );
4064 tool_info( info, parts, batch, debug );
4065 component_info( info, parts, batch, debug );
4066 qualities_info( info, parts, batch, debug );
4067
4068 // Uses for item (bandaging quality, holster capacity, grenade activation)
4070 for( const std::pair<const std::string, use_function> &method : type->use_methods ) {
4072 method.second.dump_info( *this, info );
4073 }
4074 }
4075
4076 repair_info( info, parts, batch, debug );
4077 disassembly_info( info, parts, batch, debug );
4078
4079 final_info( info, parts_ref, batch, debug );
4080
4081 if( !info.empty() && info.back().sName == "--" ) {
4082 info.pop_back();
4083 }
4084
4085 return info;
4086}
void gunmod_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2385
gun_mode gun_current_mode() const
Get the current mode for this gun (or an invalid mode if item is not a gun)
Definition: item.cpp:7899
void contents_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3565
void animal_armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2737
void med_info(const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1646
void disassembly_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3196
void combat_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3420
bool is_med_container() const
Definition: item.cpp:6625
void qualities_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3250
void gun_info(const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2022
void component_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3151
void repair_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3175
void magazine_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1886
void food_info(const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
Definition: item.cpp:1675
void armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2554
void battery_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3084
void ammo_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1909
void basic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1463
void final_info(std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
Definition: item.cpp:3648
void book_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2919
void tool_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3103
void container_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3056
@ DESCRIPTION_AUX_GUNMOD_HEADER

References _, ammo_info(), animal_armor_info(), armor_info(), basic_info(), battery_info(), book_info(), combat_info(), component_info(), container_info(), contents, contents_info(), debug, debug_mode, DESCRIPTION_AUX_GUNMOD_HEADER, DESCRIPTION_USE_METHODS, disassembly_info(), final_info(), food_info(), item_contents::front(), g, get_food(), gun_current_mode(), gun_info(), gunmod_info(), info(), insert_separation_line(), is_gun(), is_gunmod(), is_med_container(), is_medication(), is_null(), magazine_info(), med_info(), qualities_info(), repair_info(), string_format(), iteminfo_query::test(), tname(), tool_info(), type, and itype::use_methods.

◆ info() [3/4]

std::vector< iteminfo > item::info ( int  batch) const

Definition at line 3998 of file item.cpp.

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

◆ info() [4/4]

std::vector< iteminfo > item::info ( temperature_flag  temperature) const

Definition at line 4003 of file item.cpp.

4004{
4005 return info( iteminfo_query::all, 1, temperature );
4006}
static const iteminfo_query all

References iteminfo_query::all, and info().

◆ info_string() [1/2]

std::string item::info_string ( ) const

As info, but as a string rather than a vector of properties.

Definition at line 4088 of file item.cpp.

4089{
4090 return info_string( iteminfo_query::all, 1 );
4091}

References iteminfo_query::all, and info_string().

Referenced by battery_info(), colorized_item_description(), draw_caravan_items(), and info_string().

◆ info_string() [2/2]

std::string item::info_string ( const iteminfo_query parts,
int  batch = 1,
temperature_flag  temperature = temperature_flag::TEMP_NORMAL 
) const

Definition at line 4093 of file item.cpp.

4095{
4096 std::vector<iteminfo> item_info = info( parts, batch, temperature );
4097 return format_item_info( item_info, {} );
4098}
std::string format_item_info(const std::vector< iteminfo > &item_display, const std::vector< iteminfo > &item_compare)
Definition: output.cpp:854

References format_item_info(), and info().

◆ inherit_flags() [1/2]

void item::inherit_flags ( const item parent,
const recipe making 
)

Inherit applicable flags from the given parent item.

Parameters
parentItem to inherit from

Definition at line 985 of file crafting.cpp.

986{
987 // default behavior is to resize the clothing, which happens elsewhere
988 if( making.has_flag( flag_NO_RESIZE ) ) {
989 //If item is crafted from poor-fit components, the result is poorly fitted too
990 if( parent.has_flag( flag_VARSIZE ) ) {
992 }
993 //If item is crafted from perfect-fit components, the result is perfectly fitted too
994 if( parent.has_flag( flag_FIT ) ) {
996 }
997 }
998 for( const std::string &f : parent.item_tags ) {
999 if( json_flag::get( f ).craft_inherit() ) {
1000 set_flag( f );
1001 }
1002 }
1003 for( const std::string &f : parent.type->get_flags() ) {
1004 if( json_flag::get( f ).craft_inherit() ) {
1005 set_flag( f );
1006 }
1007 }
1008 if( parent.has_flag( flag_HIDDEN_POISON ) ) {
1009 poison = parent.poison;
1010 }
1011}
int poison
Definition: item.h:2214
bool has_flag(const std::string &flag_name) const
Definition: recipe.cpp:95
static const std::string flag_NO_RESIZE("NO_RESIZE")
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_FIT("FIT")
static const std::string flag_VARSIZE("VARSIZE")

References flag_FIT(), flag_HIDDEN_POISON(), flag_NO_RESIZE(), flag_VARSIZE(), json_flag::get(), itype::get_flags(), has_flag(), recipe::has_flag(), item_tags, poison, set_flag(), type, and unset_flag().

Referenced by complete_craft(), and inherit_flags().

◆ inherit_flags() [2/2]

void item::inherit_flags ( const std::list< item > &  parents,
const recipe making 
)

Inherit applicable flags from the given list of parent items.

Parameters
parentsItems to inherit from

Definition at line 1013 of file crafting.cpp.

1014{
1015 for( const item &parent : parents ) {
1016 inherit_flags( parent, making );
1017 }
1018}
void inherit_flags(const item &parent, const recipe &making)
Inherit applicable flags from the given parent item.
Definition: crafting.cpp:985
std::vector< item * > parents(const item &it)
Returns vector of parent containers (if any) starting with the innermost.
Definition: visitable.cpp:74

References inherit_flags(), and visitable< item >::parents().

◆ io()

template<typename Archive >
void item::io ( Archive &  archive)

Definition at line 2189 of file savegame_json.cpp.

2190{
2191
2192 itype_id orig; // original ID as loaded from JSON
2193 const auto load_type = [&]( const std::string & id ) {
2194 orig = itype_id( id );
2195 convert( item_controller->migrate_id( orig ) );
2196 };
2197
2198 const auto load_curammo = [this]( const std::string & id ) {
2199 curammo = &*item_controller->migrate_id( itype_id( id ) );
2200 };
2201 const auto load_corpse = [this]( const std::string & id ) {
2202 if( itype_id( id ).is_null() ) {
2203 // backwards compatibility, nullptr should not be stored at all
2204 corpse = nullptr;
2205 } else {
2206 corpse = &mtype_id( id ).obj();
2207 }
2208 };
2209 archive.template io<const itype>( "typeid", type, load_type, []( const itype & i ) {
2210 return i.get_id().str();
2211 }, io::required_tag() );
2212
2213 // normalize legacy saves to always have charges >= 0
2214 archive.io( "charges", charges, 0 );
2215 charges = std::max( charges, 0 );
2216
2217 archive.io( "energy", energy, 0_J );
2218
2219 archive.io( "burnt", burnt, 0 );
2220 archive.io( "poison", poison, 0 );
2221 archive.io( "frequency", frequency, 0 );
2222 archive.io( "snip_id", snip_id, snippet_id::NULL_ID() );
2223 // NB! field is named `irridation` in legacy files
2224 archive.io( "irridation", irradiation, 0 );
2225 archive.io( "bday", bday, calendar::start_of_cataclysm );
2226 archive.io( "mission_id", mission_id, -1 );
2227 archive.io( "player_id", player_id, -1 );
2228 archive.io( "item_vars", item_vars, io::empty_default_tag() );
2229 // TODO: change default to empty string
2230 archive.io( "name", corpse_name, std::string() );
2231 archive.io( "owner", owner, owner.NULL_ID() );
2232 archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
2233 archive.io( "invlet", invlet, '\0' );
2234 archive.io( "damaged", damage_, 0 );
2235 archive.io( "active", active, false );
2236 archive.io( "is_favorite", is_favorite, false );
2237 archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
2238 archive.io( "rot", rot, 0_turns );
2239 archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
2240 archive.io( "techniques", techniques, io::empty_default_tag() );
2241 archive.io( "faults", faults, io::empty_default_tag() );
2242 archive.io( "item_tags", item_tags, io::empty_default_tag() );
2243 archive.io( "components", components, io::empty_default_tag() );
2244 archive.io( "recipe_charges", recipe_charges, 1 );
2245 archive.template io<const itype>( "curammo", curammo, load_curammo,
2246 []( const itype & i ) {
2247 return i.get_id().str();
2248 } );
2249 archive.template io<const mtype>( "corpse", corpse, load_corpse,
2250 []( const mtype & i ) {
2251 return i.id.str();
2252 } );
2253 archive.io( "craft_data", craft_data_, decltype( craft_data_ )() );
2254 archive.io( "light", light.luminance, nolight.luminance );
2255 archive.io( "light_width", light.width, nolight.width );
2256 archive.io( "light_dir", light.direction, nolight.direction );
2257
2258 static const cata::value_ptr<relic> null_relic_ptr = nullptr;
2259 archive.io( "relic_data", relic_data, null_relic_ptr );
2260
2261 archive.io( "drop_token", drop_token, decltype( drop_token )() );
2262
2263 item_controller->migrate_item( orig, *this );
2264
2265 if( !Archive::is_input::value ) {
2266 return;
2267 }
2268 /* Loading has finished, following code is to ensure consistency and fixes bugs in saves. */
2269
2271
2272 double float_damage = 0;
2273 if( archive.read( "damage", float_damage ) ) {
2274 damage_ = std::min( std::max( min_damage(),
2275 static_cast<int>( float_damage * itype::damage_scale ) ),
2276 max_damage() );
2277 }
2278
2279 int note = 0;
2280 const bool note_read = archive.read( "note", note );
2281
2282 // Old saves used to only contain one of those values (stored under "poison"), it would be
2283 // loaded into a union of those members. Now they are separate members and must be set separately.
2284 if( poison != 0 && note == 0 && !type->snippet_category.empty() ) {
2285 std::swap( note, poison );
2286 }
2287 if( poison != 0 && frequency == 0 && ( typeId() == itype_radio_on || typeId() == itype_radio ) ) {
2289 }
2290 if( poison != 0 && irradiation == 0 && typeId() == itype_rad_badge ) {
2292 }
2293
2294 // erase all invalid flags (not defined in flags.json), display warning about invalid flags
2295 erase_if( item_tags, [&]( const std::string & f ) {
2296 if( !json_flag::get( f ).id.is_valid() ) {
2297 debugmsg( "item of type '%s' was loaded with undefined flag '%s'.", typeId().c_str(), f );
2298 return true;
2299 } else {
2300 return false;
2301 }
2302 } );
2303
2304 if( note_read ) {
2306 } else {
2307 std::optional<std::string> snip;
2308 if( archive.read( "snippet_id", snip ) && snip ) {
2309 snip_id = snippet_id( snip.value() );
2310 }
2311 }
2312
2313 // Compatibility for item type changes: for example soap changed from being a generic item
2314 // (item::charges -1 or 0 or anything else) to comestible (and thereby counted by charges),
2315 // old saves still have invalid charges, this fixes the charges value to the default charges.
2316 if( count_by_charges() && charges <= 0 ) {
2318 }
2319 if( is_food() ) {
2320 active = true;
2321 }
2322 if( !active && item_tags.count( "WET" ) > 0 ) {
2323 // Some wet items from legacy saves may be inactive
2324 active = true;
2325 }
2326 std::string mode;
2327 if( archive.read( "mode", mode ) ) {
2328 // only for backward compatibility (nowadays mode is stored in item_vars)
2329 gun_set_mode( gun_mode_id( mode ) );
2330 }
2331
2332 // Books without any chapters don't need to store a remaining-chapters
2333 // counter, it will always be 0 and it prevents proper stacking.
2334 if( get_chapters() == 0 ) {
2335 for( auto it = item_vars.begin(); it != item_vars.end(); ) {
2336 if( it->first.compare( 0, 19, "remaining-chapters-" ) == 0 ) {
2337 item_vars.erase( it++ );
2338 } else {
2339 ++it;
2340 }
2341 }
2342 }
2343
2344 // Remove stored translated gerund in favor of storing the inscription tool type
2345 item_vars.erase( "item_label_type" );
2346 item_vars.erase( "item_note_type" );
2347
2348 // Activate corpses from old saves
2349 if( is_corpse() && !active ) {
2350 active = true;
2351 }
2352
2353 if( charges != 0 && !type->can_have_charges() ) {
2354 // Types that are known to have charges, but should not have them.
2355 // We fix it here, but it's expected from bugged saves and does not require a message.
2356 if( charge_removal_blacklist::get().count( type->get_id() ) == 0 ) {
2357 debugmsg( "Item %s was loaded with charges, but can not have any!", type->get_id() );
2358 }
2359 charges = 0;
2360 }
2361
2362 // Relic check. Kinda late, but that's how relics have to be
2363 if( relic_data ) {
2364 relic_data->check();
2365 }
2366}
bool erase_if(Col &set, Pred predicate)
Erases elements from a set that match given predicate function.
Definition: cata_utility.h:237
int player_id
Definition: item.h:2220
int mission_id
Definition: item.h:2219
int frequency
Definition: item.h:2215
int recipe_charges
Definition: item.h:2212
snippet_id migrate_hash_to_id(int hash)
Used only for legacy compatibility.
light_emission nolight
Definition: item.cpp:317
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496
const std::set< itype_id > & get()
static void load_legacy_craft_data(io::JsonObjectInputArchive &archive, T &value)
static const itype_id itype_radio("radio")
static const itype_id itype_radio_on("radio_on")
static const itype_id itype_rad_badge("rad_badge")
Tag that indicates the value of the io is some kind of container and its default value is to be empty...
Definition: cata_io.h:105
Tag that indicates the value is required and must exists in the JSON data.
Definition: cata_io.h:110
bool can_have_charges() const
Definition: itype.cpp:214
mtype_id id
Definition: mtype.h:241
string_id< translation > snippet_id
Definition: type_id.h:205

References active, bday, burnt, itype::can_have_charges(), charges, components, convert(), corpse, corpse_name, count(), cata::flat_set< T, Compare, Data >::count(), count_by_charges(), craft_data_, curammo, damage_, itype::damage_scale, debugmsg, light_emission::direction, energy, erase_if(), faults, frequency, charge_removal_blacklist::get(), json_flag::get(), get_chapters(), itype::get_id(), gun_set_mode(), base_camps::id, itype::id, invlet, irradiation, is_corpse(), is_favorite, is_food(), item(), item_controller, item_counter, item_tags, item_vars, itype_id, itype_rad_badge, itype_radio, itype_radio_on, last_rot_check, light, load_legacy_craft_data(), light_emission::luminance, max_damage(), snippet_library::migrate_hash_to_id(), min_damage(), mission_id, mtype_id, nolight, string_id< translation >::NULL_ID(), string_id< T >::NULL_ID(), old_owner, owner, player_id, poison, recipe_charges, relic_data, snip_id, SNIPPET, itype::snippet_category, calendar::start_of_cataclysm, string_id< T >::str(), cata::swap(), techniques, type, typeId(), and light_emission::width.

Referenced by deserialize(), and serialize().

◆ is_ammo()

◆ is_ammo_belt()

bool item::is_ammo_belt ( ) const

Definition at line 6577 of file item.cpp.

6578{
6579 return is_magazine() && has_flag( flag_MAG_BELT );
6580}
static const std::string flag_MAG_BELT("MAG_BELT")

References flag_MAG_BELT(), has_flag(), and is_magazine().

Referenced by Character::can_reload(), item_reload_option::item_reload_option(), avatar_action::reload(), reload(), and avatar_funcs::unload_item().

◆ is_ammo_container()

◆ is_armor()

◆ is_artifact()

bool item::is_artifact ( ) const

Definition at line 6978 of file item.cpp.

6979{
6980 return !!type->artifact;
6981}

References itype::artifact, and type.

Referenced by game::add_artifact_dreams(), iuse::artifact(), needs_processing(), and process_artifact().

◆ is_bandolier()

bool item::is_bandolier ( ) const

◆ is_battery()

bool item::is_battery ( ) const

Definition at line 6572 of file item.cpp.

6573{
6574 return !!type->battery;
6575}

References itype::battery, and type.

Referenced by battery_info(), display_name(), energy_remaining(), and mod_energy().

◆ is_bionic()

◆ is_book()

◆ is_brewable()

bool item::is_brewable ( ) const

Definition at line 6613 of file item.cpp.

6614{
6615 return !!type->brewable;
6616}

References itype::brewable, and type.

Referenced by brewing_results(), brewing_time(), final_info(), iexamine::fvat_empty(), and iexamine::fvat_full().

◆ is_bucket()

bool item::is_bucket ( ) const

Definition at line 6744 of file item.cpp.

6745{
6746 // That "preserves" part is a hack:
6747 // Currently all non-empty cans are effectively sealed at all times
6748 // Making them buckets would cause weirdness
6749 return type->container &&
6750 type->container->watertight &&
6751 !type->container->seals &&
6752 !type->container->unseals_into;
6753}

References itype::container, and type.

Referenced by can_unload_liquid(), get_remaining_capacity_for_liquid(), is_bucket_nonempty(), is_container_eligible_for_crafting(), is_funnel_container(), pick_one_up(), and iexamine::tree_maple_tapped().

◆ is_bucket_nonempty()

bool item::is_bucket_nonempty ( ) const

◆ is_comestible()

◆ is_container()

◆ is_container_empty()

◆ is_container_full()

bool item::is_container_full ( bool  allow_bucket = false) const

Whether this item has no more free capacity for its current content.

Parameters
allow_bucketAllow filling non-sealable containers

Definition at line 6852 of file item.cpp.

6853{
6854 if( is_container_empty() ) {
6855 return false;
6856 }
6857 return get_remaining_capacity_for_liquid( contents.front(), allow_bucket ) == 0;
6858}

References contents, item_contents::front(), get_remaining_capacity_for_liquid(), and is_container_empty().

Referenced by is_container_eligible_for_crafting(), is_reloadable_helper(), and avatar_action::reload().

◆ is_corpse()

bool item::is_corpse ( ) const

Whether this is a corpse item.

Corpses always have valid monster type (corpse) associated (get_mtype return a non-null pointer) and have been created with make_corpse.

Definition at line 6630 of file item.cpp.

6631{
6632 return corpse != nullptr && has_flag( flag_CORPSE );
6633}

References corpse, flag_CORPSE(), and has_flag().

Referenced by base_volume(), burn(), activity_handlers::butcher_finish(), can_revive(), color(), color_in_inventory(), component_info(), zone_manager::get_near_zone_type_for_item(), get_shelf_life(), goes_bad(), has_rotten_away(), io(), made_of(), on_damage(), process_internal(), map::process_items_in_vehicle(), processing_speed(), game::revive_corpse(), tname(), volume(), and weight().

◆ is_craft()

◆ is_dangerous()

bool item::is_dangerous ( ) const

Definition at line 9808 of file item.cpp.

9809{
9810 if( has_flag( flag_DANGEROUS ) ) {
9811 return true;
9812 }
9813
9814 // Note: Item should be dangerous regardless of what type of a container is it
9815 // Visitable interface would skip some options
9816 for( const item *it : contents.all_items_top() ) {
9817 if( it->is_dangerous() ) {
9818 return true;
9819 }
9820 }
9821 return false;
9822}
static const std::string flag_DANGEROUS("DANGEROUS")

References item_contents::all_items_top(), contents, flag_DANGEROUS(), and has_flag().

Referenced by give_item_to(), and npc::value().

◆ is_deployable()

bool item::is_deployable ( ) const

Definition at line 6963 of file item.cpp.

6964{
6965 return type->can_use( "deploy_furn" );
6966}

References itype::can_use(), and type.

Referenced by Character::invoke_item().

◆ is_emissive()

bool item::is_emissive ( ) const

Whether the item emits any light at all.

Definition at line 6958 of file item.cpp.

6959{
6960 return light.luminance > 0 || type->light_emission > 0;
6961}

References light, itype::light_emission, light_emission::luminance, and type.

Referenced by submap::load(), map::update_lum(), and submap::update_lum_add().

◆ is_engine()

bool item::is_engine ( ) const

Definition at line 6760 of file item.cpp.

6761{
6762 return !!type->engine;
6763}

References itype::engine, and type.

Referenced by is_faulty(), and tname().

◆ is_faulty()

bool item::is_faulty ( ) const

Definition at line 6780 of file item.cpp.

6781{
6782 return is_engine() ? !faults.empty() : false;
6783}
bool is_engine() const
Definition: item.cpp:6760

References faults, and is_engine().

Referenced by clear_faults(), and vehicle_part::name().

◆ is_filthy()

bool item::is_filthy ( ) const

Marks the item as filthy, so characters with squeamish trait can't wear it.

Definition at line 9988 of file item.cpp.

9989{
9990 return has_flag( flag_FILTHY ) && ( get_option<bool>( "FILTHY_MORALE" ) ||
9992}
static const std::string flag_FILTHY("FILTHY")
static const trait_id trait_SQUEAMISH("SQUEAMISH")

References flag_FILTHY(), get_avatar(), has_flag(), Character::has_trait(), and trait_SQUEAMISH.

Referenced by Character::can_wear(), color_in_inventory(), crafting::complete_disassemble(), salvage_actor::cut_up(), repair_item_actor::handle_components(), item_category::priority_zone(), activity_handlers::reload_finish(), tname(), avatar_funcs::unload_item(), and heal_actor::use().

◆ is_firearm()

bool item::is_firearm ( ) const

Does it require gunsmithing tools to repair.

Definition at line 6532 of file item.cpp.

6533{
6534 static const std::string primitive_flag( "PRIMITIVE_RANGED_WEAPON" );
6535 return is_gun() && !has_flag( primitive_flag );
6536}

References has_flag(), and is_gun().

Referenced by repair_item_actor::can_repair_target(), iuse::gun_clean(), iuse::gun_repair(), and repair_inventory_preset::is_shown().

◆ is_food()

◆ is_food_container()

bool item::is_food_container ( ) const

◆ is_fresh()

bool item::is_fresh ( ) const
inline

an item is fresh if it is capable of rotting but still has a long shelf life remaining

Definition at line 839 of file item.h.

839 {
840 return goes_bad() && get_relative_rot() < 0.1;
841 }

Referenced by comestible_inventory_preset::get_freshness(), get_freshness_description(), and tname().

◆ is_fuel()

bool item::is_fuel ( ) const

Definition at line 6770 of file item.cpp.

6771{
6772 return !!type->fuel;
6773}

References itype::fuel, and type.

Referenced by Character::can_fuel_bionic_with(), vehicle_part::consume_energy(), fuel_energy(), fuel_pump_terrain(), and has_explosion_data().

◆ is_funnel_container()

bool item::is_funnel_container ( units::volume bigger_than) const

Funnel related functions.

See weather.cpp for their usage.

Definition at line 6938 of file item.cpp.

6939{
6940 if( !is_bucket() && !is_watertight_container() ) {
6941 return false;
6942 }
6943 // TODO: consider linking funnel to item or -making- it an active item
6944 if( get_container_capacity() <= bigger_than ) {
6945 return false; // skip contents check, performance
6946 }
6947 if(
6948 contents.empty() ||
6952 bigger_than = get_container_capacity();
6953 return true;
6954 }
6955 return false;
6956}
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6734
static const itype_id itype_water_acid_weak("water_acid_weak")
static const itype_id itype_water_acid("water_acid")
static const itype_id itype_water("water")

References contents, item_contents::empty(), item_contents::front(), get_container_capacity(), is_bucket(), is_watertight_container(), itype_water, itype_water_acid, itype_water_acid_weak, and typeId().

◆ is_going_bad()

bool item::is_going_bad ( ) const
inline

an item is about to become rotten when shelf life has nearly elapsed

Definition at line 844 of file item.h.

844 {
845 return get_relative_rot() > 0.9;
846 }

Referenced by get_freshness_description(), comestible_inventory_preset::get_time_left_rounded(), and tname().

◆ is_gun()

bool item::is_gun ( ) const

Can this item be used to perform a ranged attack?

See also
item::is_melee()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6527 of file item.cpp.

6528{
6529 return !!type->gun;
6530}

References itype::gun, and type.

Referenced by vehicle::add_item(), ranged::aim_per_move(), allow_crafting_component(), ammo_capacity(), ammo_consume(), character_funcs::ammo_count_for(), ammo_data(), ammo_effects(), ammo_info(), ammo_remaining(), ammo_required(), ammo_set(), ammo_sort_name(), ammo_types(), ammo_unset(), npc_ai::best_mode_for_range(), can_fire_turret(), avatar_action::can_fire_weapon(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), defense_game::caravan(), casings_handle(), npc::character_danger(), npc::check_or_use_weapon_cbm(), color_in_inventory(), npc::confident_shoot_range(), contents_info(), contextualize_skill(), damage_melee(), display_name(), durability_indicator(), final_info(), character_funcs::find_ammo_helper(), character_funcs::find_reloadables(), fire(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), character_funcs::fmt_wielded_weapon(), npc::form_opinion(), ranged::get_aim_types(), get_covered_body_parts(), get_encumber_when_containing(), get_free_mod_locations(), ranged::get_most_accurate_sight(), get_reload_time(), give_item_to(), gun_all_modes(), gun_cycle_mode(), gun_damage(), gun_dispersion(), gun_get_mode(), gun_get_mode_id(), gun_noise(), gun_range(), gun_recoil(), gun_set_mode(), gun_skill(), gunmod_info(), game::handle_action(), ranged::handle_gun_damage(), has_flag(), Character::i_add(), ideal_ranged_dps(), info(), character_effects::intimidation(), is_firearm(), is_gunmod_compatible(), is_reloadable(), gunmod_inventory_preset::is_shown(), saw_barrel_inventory_preset::is_shown(), saw_stock_inventory_preset::is_shown(), vehicle_part::is_turret(), Character::item_reload_cost(), Character::item_store_cost(), magazine_compatible(), magazine_default(), magazine_integral(), Item_modifier::modify(), item_reload_option::moves(), Character::on_dodge(), on_wield(), parse_tags(), tutorial_game::post_action(), Character::power_rating(), reach_range(), activity_handlers::reload_finish(), remove_ammo(), item_funcs::shots_remaining(), sight_dispersion(), starting_inv(), tname(), game::try_get_right_click_action(), character_funcs::try_wield_contents(), npc::value(), visit_internal(), volume(), weapon_inventory_preset::weapon_inventory_preset(), weight(), and npc::wield_better_weapon().

◆ is_gunmod()

◆ is_gunmod_compatible()

ret_val< bool > item::is_gunmod_compatible ( const item mod) const

Definition at line 7761 of file item.cpp.

7762{
7763 if( !mod.is_gunmod() ) {
7764 debugmsg( "Tried checking compatibility of non-gunmod" );
7766 }
7767 const islot_gunmod &g_mod = *mod.type->gunmod;
7768
7769 if( !is_gun() ) {
7770 return ret_val<bool>::make_failure( _( "isn't a weapon" ) );
7771
7772 } else if( is_gunmod() ) {
7773 return ret_val<bool>::make_failure( _( "is a gunmod and cannot be modded" ) );
7774
7775 } else if( gunmod_find( mod.typeId() ) ) {
7776 return ret_val<bool>::make_failure( _( "already has a %s" ), mod.tname( 1 ) );
7777
7778 } else if( !get_mod_locations().count( g_mod.location ) ) {
7779 return ret_val<bool>::make_failure( _( "doesn't have a slot for this mod" ) );
7780
7781 } else if( get_free_mod_locations( g_mod.location ) <= 0 ) {
7782 return ret_val<bool>::make_failure( _( "doesn't have enough room for another %s mod" ),
7783 mod.type->gunmod->location.name() );
7784
7785 } else if( !g_mod.usable.empty() || !g_mod.usable_category.empty() ) {
7786 bool usable = g_mod.usable.count( this->typeId() );
7787 for( const std::unordered_set<weapon_category_id> &mod_cat : g_mod.usable_category ) {
7788 if( usable ) {
7789 break;
7790 }
7791 if( std::all_of( mod_cat.begin(), mod_cat.end(), [this]( const weapon_category_id & wcid ) {
7792 return this->type->weapon_category.count( wcid );
7793 } ) ) {
7794 usable = true;
7795 }
7796 }
7797 if( !usable ) {
7798 return ret_val<bool>::make_failure( _( "cannot have a %s" ), mod.tname() );
7799 }
7800
7801 } else if( g_mod.location.str() == "underbarrel" &&
7803 return ret_val<bool>::make_failure( _( "can only accept small mods on that slot" ) );
7804
7805 } else if( !mod.type->mod->acceptable_ammo.empty() ) {
7806 bool compat_ammo = false;
7807 for( const ammotype &at : mod.type->mod->acceptable_ammo ) {
7808 if( ammo_types( false ).count( at ) ) {
7809 compat_ammo = true;
7810 }
7811 }
7812 if( !compat_ammo ) {
7814 _( "%1$s cannot be used on item with no compatible ammo types" ), mod.tname( 1 ) );
7815 }
7816 } else if( mod.typeId() == itype_waterproof_gunmod && has_flag( flag_WATERPROOF_GUN ) ) {
7817 return ret_val<bool>::make_failure( _( "is already waterproof" ) );
7818
7819 } else if( mod.typeId() == itype_tuned_mechanism && has_flag( flag_NEVER_JAMS ) ) {
7820 return ret_val<bool>::make_failure( _( "is already eminently reliable" ) );
7821
7822 } else if( mod.typeId() == itype_brass_catcher && has_flag( flag_RELOAD_EJECT ) ) {
7823 return ret_val<bool>::make_failure( _( "cannot have a brass catcher" ) );
7824
7825 } else if( ( !mod.type->mod->ammo_modifier.empty() || !mod.type->mod->magazine_adaptor.empty() )
7826 && ( ammo_remaining() > 0 || magazine_current() ) ) {
7827 return ret_val<bool>::make_failure( _( "must be unloaded before installing this mod" ) );
7828 }
7829
7830 for( const gunmod_location &slot : mod.type->gunmod->blacklist_mod ) {
7831 if( get_mod_locations().count( slot ) ) {
7832 return ret_val<bool>::make_failure( _( "cannot be installed on a weapon with \"%s\"" ),
7833 slot.name() );
7834 }
7835 }
7836
7838}
std::string name() const
Returns the translated name.
Definition: itype.cpp:15
std::string str() const
Returns the location id.
Definition: itype.h:86
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
static const std::string flag_RELOAD_EJECT("RELOAD_EJECT")
static const itype_id itype_brass_catcher("brass_catcher")
static const itype_id itype_waterproof_gunmod("waterproof_gunmod")
static const itype_id itype_tuned_mechanism("tuned_mechanism")
static const std::string flag_PUMP_ACTION("PUMP_ACTION")
static const std::string flag_NEVER_JAMS("NEVER_JAMS")
static const std::string flag_WATERPROOF_GUN("WATERPROOF_GUN")
static const std::string flag_PUMP_RAIL_COMPATIBLE("PUMP_RAIL_COMPATIBLE")
gunmod_location location
Where is this gunmod installed (e.g.
Definition: itype.h:549
std::vector< std::unordered_set< weapon_category_id > > usable_category
Definition: itype.h:553
std::unordered_set< itype_id > usable
What kind of weapons can this gunmod be used with (e.g.
Definition: itype.h:552

References _, ammo_remaining(), ammo_types(), count(), debugmsg, flag_NEVER_JAMS(), flag_PUMP_ACTION(), flag_PUMP_RAIL_COMPATIBLE(), flag_RELOAD_EJECT(), flag_WATERPROOF_GUN(), get_free_mod_locations(), get_mod_locations(), gunmod_find(), has_flag(), is_gun(), is_gunmod(), itype_brass_catcher, itype_tuned_mechanism, itype_waterproof_gunmod, islot_gunmod::location, magazine_current(), ret_val< T >::make_failure(), ret_val< T >::make_success(), gunmod_location::name(), gunmod_location::str(), typeId(), islot_gunmod::usable, and islot_gunmod::usable_category.

Referenced by gunmod_inventory_preset::get_denial(), avatar_funcs::gunmod_add(), and activity_handlers::gunmod_add_finish().

◆ is_holster()

bool item::is_holster ( ) const

Definition at line 6587 of file item.cpp.

6588{
6589 return type->can_use( "holster" );
6590}

References itype::can_use(), and type.

Referenced by character_funcs::find_reloadables(), and get_total_capacity().

◆ is_irremovable()

bool item::is_irremovable ( ) const

Definition at line 6785 of file item.cpp.

6786{
6787 return has_flag( flag_IRREMOVABLE );
6788}
static const std::string flag_IRREMOVABLE("IRREMOVABLE")

References flag_IRREMOVABLE(), and has_flag().

Referenced by allow_crafting_component(), detach_gunmods_actor::can_use(), remove_ammo(), and detach_gunmods_actor::use().

◆ is_magazine()

◆ is_map()

bool item::is_map ( ) const

Definition at line 6724 of file item.cpp.

6725{
6726 return get_category().get_id() == itemcat_maps;
6727}
item_category_id get_id() const
static const item_category_id itemcat_maps("maps")

References get_category(), item_category::get_id(), and itemcat_maps.

Referenced by map::add_item(), and display_name().

◆ is_med_container()

bool item::is_med_container ( ) const

Definition at line 6625 of file item.cpp.

6626{
6627 return !contents.empty() && contents.front().is_medication();
6628}

References contents, item_contents::empty(), item_contents::front(), and is_medication().

Referenced by info().

◆ is_medication()

◆ is_melee() [1/2]

bool item::is_melee ( ) const

Is this item an effective melee weapon for any damage type?

See also
item::is_gun()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6677 of file item.cpp.

6678{
6679 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
6680 if( is_melee( static_cast<damage_type>( idx ) ) ) {
6681 return true;
6682 }
6683 }
6684 return false;
6685}

References DT_NULL, is_melee(), and NUM_DT.

Referenced by contextualize_skill(), is_melee(), melee_skill(), and on_wield().

◆ is_melee() [2/2]

bool item::is_melee ( damage_type  dt) const

Is this item an effective melee weapon for the given damage type?

Definition at line 6687 of file item.cpp.

6688{
6689 return damage_melee( dt ) > MELEE_STAT;
6690}
static constexpr int MELEE_STAT

References damage_melee(), and MELEE_STAT.

Referenced by iexamine::cvdmachine(), Character::i_add(), tutorial_game::post_action(), and npc::wield_better_weapon().

◆ is_money()

bool item::is_money ( ) const

Definition at line 6010 of file item.cpp.

6011{
6012 return ammo_types().count( ammotype( "money" ) );
6013}

References ammo_types().

Referenced by ammo_set(), display_name(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), operator<(), and stacks_with().

◆ is_non_resealable_container()

bool item::is_non_resealable_container ( ) const

Whether removing this item's contents will permanently alter it.

Definition at line 6739 of file item.cpp.

6740{
6741 return type->container && !type->container->seals && type->container->unseals_into;
6742}

References itype::container, and type.

Referenced by deserialize(), advanced_inventory::move_content(), and on_contents_changed().

◆ is_null()

bool item::is_null ( ) const

Definition at line 737 of file item.cpp.

738{
739 // Actually, type should never by null at all.
740 return ( type == nullptr || type == nullitem() || typeId().is_null() );
741}

References is_null(), nullitem(), type, and typeId().

Referenced by acid_resist(), npc::address_needs(), ammo_set(), base_volume(), bash_resist(), Character::block_hit(), Character::block_ranged_hit(), bullet_resist(), Character::can_eat(), vehicle_part::can_reload(), repair_item_actor::can_repair_target(), Character::can_use(), debug_menu::character_edit_menu(), color(), colorized_feature_description_at(), veh_interact::complete_vehicle(), conductive(), Character::consume_item(), cut_resist(), damage_melee(), display_name(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), drop_or_embed_projectile(), enumerate_objects_around_point(), Character::extended_description(), final_info(), find_auto_consume(), fire_resist(), inventory::form_from_map(), iexamine::gaspump(), liquid_handler::get_liquid_target(), SkillLevelMap::get_skill_level(), aim_activity_actor::get_weapon(), Character::handle_melee_wear(), npc::has_healing_item(), npc::heal_player(), npc::heal_self(), info(), npc_trading::init_buying(), Character::is_armed(), is_null(), is_old_owner(), is_owned_by(), is_salvageable(), is_unarmed_weapon(), Character::item_encumb(), Character::item_reload_cost(), npc::load(), made_of(), Character::meets_requirements(), Character::melee_attack(), melee_train(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), monexamine::pet_menu(), photo_def_for_camera_point(), player::reduce_charges(), reinforceable(), bandolier_actor::reload(), reload(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), projectile::set_drop(), set_snippet(), npc::shop_restock(), map::spawn_items(), starting_inv(), Character::store(), npc::store(), holster_actor::store(), Character::suffer_from_schizophrenia(), Character::throw_range(), tname(), salvage_actor::try_to_cut_up(), Character::unarmed_attack(), Character::unwield(), avatar_funcs::use_item(), npc::use_painkiller(), salvage_actor::valid_to_cut_up(), volume(), martialart::weapon_valid(), Character::wear_possessed(), weight(), npc::wield(), avatar::wield(), and npc::wield_better_weapon().

◆ is_old_owner()

bool item::is_old_owner ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1254 of file item.cpp.

1255{
1256 if( get_old_owner().is_null() ) {
1257 return available_to_take;
1258 }
1259 if( !c.get_faction() ) {
1260 debugmsg( "Character %s has no faction.", c.disp_name() );
1261 return false;
1262 }
1263 return c.get_faction()->id == get_old_owner();
1264}
faction_id get_old_owner() const
Definition: item.cpp:1290

References c, debugmsg, get_old_owner(), and is_null().

◆ is_owned_by()

bool item::is_owned_by ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1239 of file item.cpp.

1240{
1241 // owner.is_null() implies faction_id( "no_faction" ) which shouldn't happen, or no owner at all.
1242 // either way, certain situations this means the thing is available to take.
1243 // in other scenarios we actually really want to check for id == id, even for no_faction
1244 if( get_owner().is_null() ) {
1245 return available_to_take;
1246 }
1247 if( !c.get_faction() ) {
1248 debugmsg( "Character %s has no faction", c.disp_name() );
1249 return false;
1250 }
1251 return c.get_faction()->id == get_owner();
1252}

References c, debugmsg, get_owner(), and is_null().

Referenced by activity_on_turn_move_loot(), move_items_activity_actor::do_turn(), find_auto_consume(), handle_pickup_ownership(), npc_trading::init_buying(), pick_one_up(), pickup::pick_up(), query_consume_ownership(), and npc::wants_to_sell().

◆ is_pet_armor()

bool item::is_pet_armor ( bool  on_pet = false) const

Definition at line 6708 of file item.cpp.

6709{
6710 bool is_worn = on_pet && !get_var( "pet_armor", "" ).empty();
6711 return has_flag( flag_IS_PET_ARMOR ) && ( is_worn || !on_pet );
6712}
static const std::string flag_IS_PET_ARMOR("IS_PET_ARMOR")

References flag_IS_PET_ARMOR(), get_var(), and has_flag().

Referenced by animal_armor_info(), armor_protection_info(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_storage(), and get_thickness().

◆ is_power_armor()

bool item::is_power_armor ( ) const

Whether this is a power armor item.

Not necessarily the main armor, it could be a helmet or similar.

Definition at line 5796 of file item.cpp.

5797{
5800}
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by armor_fit_info(), Character::can_wear(), Character::consume_charges(), final_info(), Character::has_enough_charges(), process_tool(), units_remaining(), and set_transform_iuse::use().

◆ is_relic()

bool item::is_relic ( ) const

Definition at line 6983 of file item.cpp.

6984{
6985 return !!relic_data;
6986}

References relic_data.

Referenced by get_enchantments(), mutations_from_wearing(), process_relic(), and stacks_with().

◆ is_reloadable()

bool item::is_reloadable ( ) const

Is it ever possible to reload this item? Only the base item is considered with any mods ignored.

See also
player::can_reload()

Definition at line 9837 of file item.cpp.

9838{
9840 return false; // turrets ignore NO_RELOAD flag
9841
9842 } else if( is_bandolier() ) {
9843 return true;
9844
9845 } else if( is_container() ) {
9846 return true;
9847
9848 } else if( !is_gun() && !is_tool() && !is_magazine() ) {
9849 return false;
9850
9851 } else if( ammo_types().empty() ) {
9852 return false;
9853 }
9854
9855 return true;
9856}
static const std::string flag_VEHICLE("VEHICLE")

References ammo_types(), flag_NO_RELOAD(), flag_VEHICLE(), has_flag(), is_bandolier(), is_container(), is_gun(), is_magazine(), and is_tool().

Referenced by can_reload_item_or_mods(), is_reloadable_helper(), and examine_item_menu::rate_action_reload().

◆ is_reloadable_helper()

bool item::is_reloadable_helper ( const itype_id ammo,
bool  now 
) const
private

Helper for checking reloadability.

Definition at line 6886 of file item.cpp.

6887{
6888 // empty ammo is passed for listing possible ammo apparently, so it needs to return true.
6889 if( !is_reloadable() ) {
6890 return false;
6891 } else if( is_watertight_container() ) {
6892 if( ammo.is_empty() ) {
6893 return now ? !is_container_full() : true;
6894 } else if( ammo->phase != LIQUID ) {
6895 return false;
6896 } else {
6897 return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
6898 }
6899 } else if( magazine_integral() ) {
6900 if( !ammo.is_empty() ) {
6901 if( now && ammo_data() ) {
6902 if( ammo_current() != ammo ) {
6903 return false;
6904 }
6905 } else {
6906 const itype *at = &*ammo;
6907 if( ( !at->ammo || !ammo_types().count( at->ammo->type ) ) &&
6908 !magazine_compatible().count( ammo ) ) {
6909 return false;
6910 }
6911 }
6912 }
6913 return now ? ( ammo_remaining() < ammo_capacity() ) : true;
6914 } else {
6915 return ammo.is_empty() ? true : magazine_compatible().count( ammo );
6916 }
6917}
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9837
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6852

References itype::ammo, ammo_capacity(), ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), contents, count(), item_contents::front(), is_container_empty(), is_container_full(), string_id< T >::is_empty(), is_reloadable(), is_watertight_container(), LIQUID, magazine_compatible(), magazine_integral(), itype::phase, and typeId().

Referenced by can_reload_with(), and is_reloadable_with().

◆ is_reloadable_with()

bool item::is_reloadable_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo type at this moment.

Definition at line 6881 of file item.cpp.

6882{
6883 return is_reloadable_helper( ammo, true );
6884}

References is_reloadable_helper().

Referenced by Character::can_reload(), vehicle_part::can_reload(), fill_with(), get_remaining_capacity_for_liquid(), and reload().

◆ is_salvageable()

bool item::is_salvageable ( ) const

Definition at line 6919 of file item.cpp.

6920{
6921 if( is_null() ) {
6922 return false;
6923 }
6924 const std::vector<material_id> &mats = made_of();
6925 if( std::none_of( mats.begin(), mats.end(), []( const material_id & m ) {
6926 return m->salvaged_into().has_value();
6927 } ) ) {
6928 return false;
6929 }
6930 return !has_flag( flag_NO_SALVAGE );
6931}
static const std::string flag_NO_SALVAGE("NO_SALVAGE")

References flag_NO_SALVAGE(), has_flag(), is_null(), and made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ is_seed()

bool item::is_seed ( ) const

Whether this is actually a seed, the seed functions won't be of much use for non-seeds.

Definition at line 9781 of file item.cpp.

9782{
9783 return !!type->seed;
9784}

References itype::seed, and type.

Referenced by can_do_activity_there(), iexamine::dirtmound(), farm_valid_seed(), talk_function::field_plant(), plot_options::get_zone_name_suggestion(), plot_options::query_seed(), vehicle::reload_seeds(), and map::rotten_item_spawn().

◆ is_sided()

bool item::is_sided ( ) const

Returns true if item is armor and can be worn on different sides of the body.

Definition at line 807 of file item.cpp.

808{
809 const islot_armor *t = find_armor_data();
810 return t ? t->sided : false;
811}

References find_armor_data(), and islot_armor::sided.

Referenced by armor_fit_info(), armor_info(), Character::can_wear(), on_takeoff(), on_wear(), examine_item_menu::rate_action_change_side(), and set_side().

◆ is_silent()

bool item::is_silent ( ) const

Whether this is a (nearly) silent gun (a tiny bit of sound is allowed).

Non-guns are always silent.

Definition at line 6552 of file item.cpp.

6553{
6554 return gun_noise().volume < 5;
6555}
sound_data gun_noise(bool burst=false) const
Returns the sound of the gun being fired.
Definition: ranged.cpp:1813
int volume
Volume of the sound.
Definition: item.h:1860

References gun_noise(), and item::sound_data::volume.

Referenced by npc::check_or_use_weapon_cbm(), and npc::method_of_attack().

◆ is_soft()

bool item::is_soft ( ) const

Is this item flexible enough to be worn on body parts like antlers?

Definition at line 9829 of file item.cpp.

9830{
9831 const std::vector<material_id> mats = made_of();
9832 return std::any_of( mats.begin(), mats.end(), []( const material_id & mid ) {
9833 return mid.obj().soft();
9834 } );
9835}

References made_of().

Referenced by mutation_branch::conflicts_with_item(), and game_menus::inv::multiwash().

◆ is_tainted()

bool item::is_tainted ( ) const

Is item derived from a zombie?

Definition at line 9824 of file item.cpp.

9825{
9826 return corpse && corpse->has_flag( MF_POISON );
9827}
@ MF_POISON
Definition: mtype.h:80

References corpse, mtype::has_flag(), and MF_POISON.

Referenced by food_info().

◆ is_tool()

◆ is_toolmod()

bool item::is_toolmod ( ) const

Definition at line 6775 of file item.cpp.

6776{
6777 return !is_gunmod() && type->mod;
6778}

References is_gunmod(), itype::mod, and type.

Referenced by allow_crafting_component(), item_action_generator::map_actions_to_items(), iuse::multicooker(), and iuse::toolmod_attach().

◆ is_transformable()

bool item::is_transformable ( ) const

Definition at line 6973 of file item.cpp.

6974{
6975 return type->use_methods.find( "transform" ) != type->use_methods.end();
6976}

References type, and itype::use_methods.

Referenced by map::add_item().

◆ is_two_handed()

bool item::is_two_handed ( const Character guy) const

Whether the character needs both hands to wield this item.

Strength determines which weapons can be wielded with one hand

Definition at line 6414 of file item.cpp.

6415{
6416 if( has_flag( flag_ALWAYS_TWOHAND ) ) {
6417 return true;
6418 }
6419 ///\EFFECT_STR determines which weapons can be wielded with one hand
6420 return ( ( weight() / 113_gram ) > guy.str_cur * 4 );
6421}
int str_cur
Definition: character.h:264
static const std::string flag_ALWAYS_TWOHAND("ALWAYS_TWOHAND")

References flag_ALWAYS_TWOHAND(), has_flag(), Character::str_cur, and weight().

Referenced by Character::can_wear(), Character::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), Character::item_handling_cost(), and Character::melee_special_effects().

◆ is_unarmed_weapon()

bool item::is_unarmed_weapon ( ) const

Definition at line 743 of file item.cpp.

744{
745 return has_flag( flag_UNARMED_WEAPON ) || is_null();
746}
static const std::string flag_UNARMED_WEAPON("UNARMED_WEAPON")

References flag_UNARMED_WEAPON(), has_flag(), and is_null().

Referenced by Character::crit_chance(), melee_train(), Character::roll_bash_damage(), Character::roll_cut_damage(), and Character::roll_stab_damage().

◆ is_upgrade()

bool item::is_upgrade ( ) const

Whether the CBM is an upgrade to another bionic module.

Definition at line 10043 of file item.cpp.

10044{
10045 if( !type->bionic ) {
10046 return false;
10047 }
10048 return type->bionic->is_upgrade;
10049}

References itype::bionic, and type.

Referenced by bionic_install_preset::get_denial(), and bionic_install_surgeon_preset::get_denial().

◆ is_watertight_container()

bool item::is_watertight_container ( ) const

◆ is_wheel()

bool item::is_wheel ( ) const

Definition at line 6765 of file item.cpp.

6766{
6767 return !!type->wheel;
6768}
cata::value_ptr< islot_wheel > wheel
Definition: itype.h:828

References type, and itype::wheel.

Referenced by can_do_activity_there(), tname(), wheel_area(), vehicle_part::wheel_diameter(), and vehicle_part::wheel_width().

◆ is_worn_only_with()

bool item::is_worn_only_with ( const item it) const

Returns true whether this item can be worn only when.

Parameters
itis worn.

Definition at line 840 of file item.cpp.

841{
844}

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by Character::get_dependent_worn_items(), and pickup::reorder_for_dropping().

◆ item_has_uses_recursive()

bool item::item_has_uses_recursive ( ) const

Definition at line 80 of file item_action.cpp.

81{
82 if( !type->use_methods.empty() ) {
83 return true;
84 }
85
87}
bool item_has_uses_recursive() const
Definition: item_action.cpp:89

References contents, item_contents::item_has_uses_recursive(), type, and itype::use_methods.

◆ label()

std::string item::label ( unsigned int  quantity = 0) const

Returns label from "item_label" itemvar and quantity.

Definition at line 9959 of file item.cpp.

9960{
9961 if( has_label() ) {
9962 return get_var( "item_label" );
9963 }
9964
9965 return type_name( quantity );
9966}
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9858
bool has_label() const
Returns true if item has "item_label" itemvar.
Definition: item.cpp:9954

References get_var(), has_label(), and type_name().

Referenced by tname().

◆ legacy_fast_forward_time()

void item::legacy_fast_forward_time ( )

Definition at line 10022 of file item.cpp.

10023{
10024 const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
10025 bday = calendar::turn_zero + tmp_bday;
10026
10027 rot *= 6;
10028
10029 const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
10031}

References bday, last_rot_check, and calendar::turn_zero.

Referenced by deserialize(), and submap::load().

◆ lift_strength()

int item::lift_strength ( ) const

Required strength to be able to successfully lift the item unaided by equipment.

Definition at line 5202 of file item.cpp.

5203{
5204 const int mass = units::to_gram( weight() );
5205 return std::max( mass / 10000, 1 );
5206}
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
quantity< std::int64_t, mass_in_milligram_tag > mass
Definition: units_mass.h:23

References units::to_gram(), and weight().

Referenced by can_do_activity_there(), veh_interact::can_remove_part(), and veh_interact::update_part_requirements().

◆ made_of() [1/3]

const std::vector< material_id > & item::made_of ( ) const

The ids of all the materials this is made of.

This may return an empty vector. The returned vector does not contain the null id.

Definition at line 6423 of file item.cpp.

6424{
6425 if( is_corpse() ) {
6426 return corpse->mat;
6427 }
6428 return type->materials;
6429}
std::vector< material_id > materials
Definition: itype.h:893
std::vector< material_id > mat
Definition: mtype.h:255

References corpse, is_corpse(), mtype::mat, itype::materials, and type.

Referenced by activity_on_turn_move_loot(), map::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), iuse::blech(), iuse::blech_because_unclean(), vehicle_part::can_reload(), can_unload_liquid(), saw_stock_actor::can_use_on(), Character::can_wear(), Character::can_wield(), MonsterGenerator::check_monster_definitions(), color_in_inventory(), crafting::complete_disassemble(), compute_default_effective_vitamins(), contents_made_of(), map::create_burnproducts(), auto_pickup::rule_list::create_rule(), salvage_actor::cut_up(), iexamine::cvdmachine(), move_items_activity_actor::do_turn(), Character::drop_invalid_inventory(), drop_or_handle(), final_info(), character_funcs::find_ammo_helper(), iexamine::fvat_empty(), iexamine::fvat_full(), Character::get_acquirable_energy(), get_base_material(), pickup_inventory_preset::get_denial(), comestible_inventory_preset::get_denial(), liquid_handler::get_liquid_target(), get_random_material(), repair_item_actor::handle_components(), liquid_handler::handle_liquid(), Character::i_add_or_drop(), in_container(), is_salvageable(), is_soft(), inscribe_actor::item_inscription(), iexamine::keg(), made_of(), made_of_any(), made_of_types(), Character::melee_special_effects(), Item_modifier::modify(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_pickup_from_stack(), on_drop(), only_made_of(), liquid_handler::perform_liquid_transfer(), pick_one_up(), price(), monster::process_turn(), mattack::pull_metal_weapon(), item_reload_option::qty(), advanced_inventory::query_charges(), reload(), simulate_burn(), smash(), map::spawn_an_item(), starting_inv(), ranged::throw_item(), tname(), try_fuel_fire(), avatar_funcs::unload_item(), npc::value(), visit_salvage_products(), volume(), and Character::warmth().

◆ made_of() [2/3]

bool item::made_of ( const material_id mat_ident) const

Check we are made of this material (e.g.

matches at least one in our set.)

Definition at line 6469 of file item.cpp.

6470{
6471 const std::vector<material_id> &materials = made_of();
6472 return std::find( materials.begin(), materials.end(), mat_ident ) != materials.end();
6473}

References detail::find(), and made_of().

◆ made_of() [3/3]

bool item::made_of ( phase_id  phase) const

Are we solid, liquid, gas, plasma?

Definition at line 6480 of file item.cpp.

6481{
6482 if( is_null() ) {
6483 return false;
6484 }
6485 return type->phase == phase;
6486}

References is_null(), itype::phase, and type.

◆ made_of_any()

bool item::made_of_any ( const std::set< material_id > &  mat_idents) const

Check we are made of at least one of a set (e.g.

true if at least one item of the passed in set matches any material).

Parameters
mat_identsSet of material ids.

Definition at line 6445 of file item.cpp.

6446{
6447 const std::vector<material_id> &mats = made_of();
6448 if( mats.empty() ) {
6449 return false;
6450 }
6451
6452 return std::any_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6453 return mat_idents.count( e );
6454 } );
6455}

References made_of().

Referenced by Character::can_eat(), goes_bad(), repair_inventory_preset::is_shown(), inscribe_actor::item_inscription(), ranged::throw_item(), and Character::throw_range().

◆ made_of_types()

std::vector< const material_type * > item::made_of_types ( ) const

Same as made_of(), but returns the material_type directly.

Definition at line 6436 of file item.cpp.

6437{
6438 std::vector<const material_type *> material_types_composed_of;
6439 for( const material_id &mat_id : made_of() ) {
6440 material_types_composed_of.push_back( &mat_id.obj() );
6441 }
6442 return material_types_composed_of;
6443}

References made_of().

Referenced by acid_resist(), bash_resist(), basic_info(), bullet_resist(), chip_resistance(), conductive(), cut_resist(), fire_resist(), flammable(), reinforceable(), and wind_resist().

◆ magazine_compatible()

std::set< itype_id > item::magazine_compatible ( bool  conversion = true) const

Get compatible magazines (if any) for this item.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine compatibility which is always empty if item has integral magazine
See also
item::magazine_integral

Definition at line 7698 of file item.cpp.

7699{
7700 std::set<itype_id> mags = {};
7701 // mods that define magazine_adaptor may override the items usual magazines
7702 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7703 for( const item *m : mods ) {
7704 if( !m->type->mod->magazine_adaptor.empty() ) {
7705 for( const ammotype &atype : ammo_types( conversion ) ) {
7706 if( m->type->mod->magazine_adaptor.count( atype ) ) {
7707 std::set<itype_id> magazines_for_atype = m->type->mod->magazine_adaptor.find( atype )->second;
7708 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7709 }
7710 }
7711 return mags;
7712 }
7713 }
7714
7715 for( const ammotype &atype : ammo_types( conversion ) ) {
7716 if( type->magazines.count( atype ) ) {
7717 std::set<itype_id> magazines_for_atype = type->magazines.find( atype )->second;
7718 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7719 }
7720 }
7721 return mags;
7722}

References ammo_types(), gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by mdeath::broken(), color_in_inventory(), character_funcs::find_reloadables(), gun_info(), avatar_funcs::gunmod_add(), is_reloadable_helper(), and tool_info().

◆ magazine_current() [1/2]

item * item::magazine_current ( )

Currently loaded magazine (if any)

Returns
current magazine or nullptr if either no magazine loaded or item has integral magazine
See also
item::magazine_integral

Definition at line 7724 of file item.cpp.

7725{
7726 return contents.get_item_with(
7727 []( const item & it ) {
7728 return it.is_magazine();
7729 } );
7730}
item * get_item_with(const std::function< bool(const item &)> &filter)

References contents, item_contents::get_item_with(), and is_magazine().

Referenced by ammo_capacity(), ammo_consume(), ammo_data(), ammo_remaining(), ammo_set(), ammo_unset(), item_funcs::can_be_unloaded(), turret_data::can_unload(), common_ammo_default(), cycle_action(), iuse::foodperson(), iuse::hand_crank(), is_gunmod_compatible(), character_funcs::list_ammo(), magazine_current(), Item_modifier::modify(), reload(), character_funcs::select_ammo(), tool_info(), iuse::toolmod_attach(), avatar_funcs::unload_item(), volume(), and weight().

◆ magazine_current() [2/2]

const item * item::magazine_current ( ) const

Definition at line 7732 of file item.cpp.

7733{
7734 return const_cast<item *>( this )->magazine_current();
7735}

References magazine_current().

◆ magazine_default()

itype_id item::magazine_default ( bool  conversion = true) const

Get the default magazine type (if any) for the current effective ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine type or "null" if item has integral magazine or no magazines for current ammo type

Definition at line 7677 of file item.cpp.

7678{
7679 if( !ammo_types( conversion ).empty() ) {
7680 if( conversion ) {
7681 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7682 if( !m->type->mod->magazine_adaptor.empty() ) {
7683 auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
7684 if( mags != m->type->mod->magazine_adaptor.end() ) {
7685 return *( mags->second.begin() );
7686 }
7687 }
7688 }
7689 }
7690 auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
7691 if( mag != type->magazine_default.end() ) {
7692 return mag->second;
7693 }
7694 }
7695 return itype_id::NULL_ID();
7696}
std::map< ammotype, itype_id > magazine_default
Default magazine for each ammo type that can be used to reload this item.
Definition: itype.h:994

References ammo_types(), gunmods(), is_gun(), itype::magazine_default, itype::mod, string_id< itype >::NULL_ID(), toolmods(), and type.

Referenced by ammo_capacity(), ammo_set(), defense_game::caravan(), game::dump_stats(), and Item_modifier::modify().

◆ magazine_info()

void item::magazine_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1886 of file item.cpp.

1888{
1889 if( !is_magazine() || has_flag( flag_NO_RELOAD ) ) {
1890 return;
1891 }
1892
1893 if( parts->test( iteminfo_parts::MAGAZINE_CAPACITY ) ) {
1894 for( const ammotype &at : ammo_types() ) {
1895 const std::string fmt = string_format( vgettext( "<num> round of %s",
1896 "<num> rounds of %s", ammo_capacity() ),
1897 at->name() );
1898 info.emplace_back( "MAGAZINE", _( "Capacity: " ), fmt, iteminfo::no_flags,
1899 ammo_capacity() );
1900 }
1901 }
1902 if( parts->test( iteminfo_parts::MAGAZINE_RELOAD ) ) {
1903 info.emplace_back( "MAGAZINE", _( "Reload time: " ), _( "<num> moves per round" ),
1904 iteminfo::lower_is_better, type->magazine->reload_time );
1905 }
1907}

References _, ammo_capacity(), ammo_types(), flag_NO_RELOAD(), has_flag(), info(), insert_separation_line(), is_magazine(), iteminfo::lower_is_better, itype::magazine, MAGAZINE_CAPACITY, MAGAZINE_RELOAD, iteminfo::no_flags, string_format(), iteminfo_query::test(), type, and vgettext().

Referenced by info().

◆ magazine_integral()

bool item::magazine_integral ( ) const

Does item have an integral magazine (as opposed to allowing detachable magazines)

Definition at line 7662 of file item.cpp.

7663{
7664 if( is_gun() && type->gun->clip > 0 ) {
7665 return true;
7666 }
7667 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7668 if( !m->type->mod->magazine_adaptor.empty() ) {
7669 return false;
7670 }
7671 }
7672
7673 // We have an integral magazine if we're a gun with an ammo capacity (clip) or we have no magazines.
7674 return ( is_gun() && type->gun->clip > 0 ) || type->magazines.empty();
7675}

References itype::gun, gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by character_funcs::ammo_count_for(), ammo_set(), ammo_unset(), turret_data::can_reload(), defense_game::caravan(), color_in_inventory(), game::dump_stats(), character_funcs::fmt_wielded_weapon(), gun_info(), avatar_funcs::gunmod_add(), ideal_ranged_dps(), is_reloadable_helper(), item(), Item_modifier::modify(), price(), reload(), character_funcs::select_ammo(), tool_info(), wants_to_reload_with(), and weight().

◆ make_component_hash()

uint64_t item::make_component_hash ( ) const

Creates a hash from the itype_ids of this item's components.

Definition at line 8919 of file item.cpp.

8920{
8921 // First we need to sort the IDs so that identical ingredients give identical hashes.
8922 std::multiset<std::string> id_set;
8923 for( const item &it : components ) {
8924 id_set.insert( it.typeId().str() );
8925 }
8926
8927 std::string concatenated_ids;
8928 for( std::string id : id_set ) {
8929 concatenated_ids += id;
8930 }
8931
8932 std::hash<std::string> hasher;
8933 return hasher( concatenated_ids );
8934}

References components, base_camps::id, and string_id< T >::str().

Referenced by consumption_event::consumption_event(), and Character::fun_for().

◆ make_corpse()

item item::make_corpse ( const mtype_id mt = string_id<mtype>::NULL_ID(),
time_point  turn = calendar::turn,
const std::string &  name = "",
int  upgrade_time = -1 
)
static

Make a corpse of the given monster type.

The monster type id must be valid (see MonsterGenerator::get_all_mtypes).

The turn parameter sets the birthday of the corpse, in other words: the turn when the monster died. Because corpses are removed from the map when they reach a certain age, one has to be careful when placing corpses with a birthday of 0. They might be removed immediately when the map is loaded without been seen by the player.

The name parameter can be used to give the corpse item a name. This is used instead of the monster type name ("corpse of X" instead of "corpse of bear").

With the default parameters it makes a human corpse, created at the current turn.

Definition at line 512 of file item.cpp.

514{
515 if( !mt.is_valid() ) {
516 debugmsg( "tried to make a corpse with an invalid mtype id" );
517 }
518
519 std::string corpse_type = mt == mtype_id::NULL_ID() ? "corpse_generic_human" : "corpse";
520
521 item result( corpse_type, turn );
522 result.corpse = &mt.obj();
523
524 if( result.corpse->has_flag( MF_REVIVES ) ) {
525 if( one_in( 20 ) ) {
526 result.set_flag( "REVIVE_SPECIAL" );
527 }
528 result.set_var( "upgrade_time", std::to_string( upgrade_time ) );
529 }
530
531 // This is unconditional because the const itemructor above sets result.name to
532 // "human corpse".
533 result.corpse_name = name;
534
535 return result;
536}
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
bool one_in(int chance)
Definition: rng.cpp:65

References debugmsg, string_id< T >::is_valid(), MF_REVIVES, om_direction::name(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), one_in(), to_string(), and calendar::turn.

Referenced by map::add_corpse(), game::catch_a_monster(), Single_item_creator::create_single(), map::draw_mine(), iuse::fish_trap(), basecamp::hunting_results(), make_mon_corpse(), MapExtras::mx_grave(), MapExtras::mx_mayhem(), MapExtras::mx_minefield(), Character::place_corpse(), rod_fish(), and mdeath::splatter().

◆ mark_as_used_by_player()

void item::mark_as_used_by_player ( const player p)

Marks the item as being used by this specific player, it remains unmarked for other players.

The player is identified by its id.

Definition at line 8867 of file item.cpp.

8868{
8869 std::string &used_by_ids = item_vars[ USED_BY_IDS ];
8870 if( used_by_ids.empty() ) {
8871 // *always* start with a ';'
8872 used_by_ids = ";";
8873 }
8874 // and always end with a ';'
8875 used_by_ids += string_format( "%d;", p.getID().get_value() );
8876}

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by reveal_map_actor::use().

◆ mark_chapter_as_read()

void item::mark_chapter_as_read ( const Character ch)

Mark one chapter of the book as read by the given player.

May do nothing if the book has no unread chapters. This is a per-character setting, see get_remaining_chapters.

Definition at line 7113 of file item.cpp.

7114{
7115 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7116 if( type->book && type->book->chapters == 0 ) {
7117 // books without chapters will always have remaining chapters == 0, so we don't need to store them
7118 erase_var( var );
7119 return;
7120 }
7121 const int remain = std::max( 0, get_remaining_chapters( ch ) - 1 );
7122 set_var( var, remain );
7123}
void erase_var(const std::string &name)
Erase the value of the given variable.
Definition: item.cpp:1085

References itype::book, erase_var(), get_remaining_chapters(), character_id::get_value(), Character::getID(), set_var(), string_format(), and type.

Referenced by avatar::do_read(), and npc::finish_read().

◆ max_damage()

◆ med_info()

void item::med_info ( const item med_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1646 of file item.cpp.

1648{
1649 const cata::value_ptr<islot_comestible> &med_com = med_item->get_comestible();
1650 if( med_com->quench != 0 && parts->test( iteminfo_parts::MED_QUENCH ) ) {
1651 info.push_back( iteminfo( "MED", _( "Quench: " ), med_com->quench ) );
1652 }
1653
1654 if( med_item->get_comestible_fun() != 0 && parts->test( iteminfo_parts::MED_JOY ) ) {
1655 info.push_back( iteminfo( "MED", _( "Enjoyability: " ),
1656 get_avatar().fun_for( *med_item ).first ) );
1657 }
1658
1659 if( med_com->stim != 0 && parts->test( iteminfo_parts::MED_STIMULATION ) ) {
1660 std::string name = string_format( "%s <stat>%s</stat>", _( "Stimulation:" ),
1661 med_com->stim > 0 ? _( "Upper" ) : _( "Downer" ) );
1662 info.push_back( iteminfo( "MED", name ) );
1663 }
1664
1665 if( parts->test( iteminfo_parts::MED_PORTIONS ) ) {
1666 info.push_back( iteminfo( "MED", _( "Portions: " ),
1667 std::abs( static_cast<int>( med_item->charges ) * batch ) ) );
1668 }
1669
1670 if( med_com->addict && parts->test( iteminfo_parts::DESCRIPTION_MED_ADDICTING ) ) {
1671 info.emplace_back( "DESCRIPTION", _( "* Consuming this item is <bad>addicting</bad>." ) );
1672 }
1673}
int get_comestible_fun() const
Definition: item.cpp:5509

References _, charges, DESCRIPTION_MED_ADDICTING, get_avatar(), get_comestible(), get_comestible_fun(), info(), MED_JOY, MED_PORTIONS, MED_QUENCH, MED_STIMULATION, om_direction::name(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ melee_skill()

skill_id item::melee_skill ( ) const

The most relevant skill used with this melee weapon.

Can be "null" if this is not a weapon. Note this function returns null if the item is a gun for which you can use gun_skill() instead.

Definition at line 7205 of file item.cpp.

7206{
7207 if( !is_melee() ) {
7208 return skill_id::NULL_ID();
7209 }
7210
7211 if( has_flag( flag_UNARMED_WEAPON ) ) {
7212 return skill_unarmed;
7213 }
7214
7215 int hi = 0;
7217
7218 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
7219 const int val = damage_melee( static_cast<damage_type>( idx ) );
7220 const skill_id &sk = skill_by_dt( static_cast<damage_type>( idx ) );
7221 if( val > hi && sk ) {
7222 hi = val;
7223 res = sk;
7224 }
7225 }
7226
7227 return res;
7228}
const skill_id & skill_by_dt(damage_type dt)
Definition: damage.cpp:273
static const skill_id skill_unarmed("unarmed")

References damage_melee(), DT_NULL, flag_UNARMED_WEAPON(), has_flag(), is_melee(), string_id< Skill >::NULL_ID(), NUM_DT, skill_by_dt(), and skill_unarmed.

Referenced by contextualize_skill(), Character::crit_chance(), Character::get_hit_weapon(), Character::item_store_cost(), on_wield(), and character_funcs::try_wield_contents().

◆ merge_charges()

bool item::merge_charges ( const item rhs)

Merge charges of the other item into this item.

Returns
true if the items have been merged, otherwise false. Merging is only done for items counted by charges (count_by_charges) and items that stack together (stacks_with).

Definition at line 981 of file item.cpp.

982{
983 if( !count_by_charges() || !stacks_with( rhs ) ) {
984 return false;
985 }
986 // Prevent overflow when either item has "near infinite" charges.
987 if( charges >= INFINITE_CHARGES / 2 || rhs.charges >= INFINITE_CHARGES / 2 ) {
989 return true;
990 }
991 // We'll just hope that the item counter represents the same thing for both items
992 if( item_counter > 0 || rhs.item_counter > 0 ) {
993 item_counter = ( static_cast<double>( item_counter ) * charges + static_cast<double>
994 ( rhs.item_counter ) * rhs.charges ) / ( charges + rhs.charges );
995 }
996 charges += rhs.charges;
997 return true;
998}

References charges, count_by_charges(), INFINITE_CHARGES, item_counter, and stacks_with().

◆ min_damage()

int item::min_damage ( ) const

Minimum amount of damage to an item (state of maximum repair)

Definition at line 6221 of file item.cpp.

6222{
6223 return type->damage_min();
6224}
int damage_min() const
Definition: itype.cpp:46

References itype::damage_min(), and type.

Referenced by repair_item_actor::can_repair_target(), damage_color(), repair_item_actor::default_action(), iuse::gun_repair(), io(), mod_damage(), and set_damage().

◆ minimum_freshness_duration()

time_duration item::minimum_freshness_duration ( temperature_flag  temperature) const

Time that this item is guaranteed to stay fresh.

Parameters
temperatureTemperature flag used to cap the duration.
Returns
Remaining guaranteed freshness duration, assuming current storage conditions.

Definition at line 5710 of file item.cpp.

5711{
5713 unsigned long long rot_per_hour = get_hourly_rotpoints_at_temp( temp );
5714
5715 if( rot_per_hour <= 0 || !type->comestible ) {
5717 }
5718
5719 time_duration remaining_rot = type->comestible->spoils - rot;
5720 // Has to be in int64 or it will overflow for long lasting food
5721 unsigned long long duration = to_turns<unsigned long long>( remaining_rot )
5722 * to_turns<unsigned long long>( 1_hours )
5723 / rot_per_hour;
5724 if( duration > to_turns<unsigned long long>( calendar::INDEFINITELY_LONG_DURATION ) ) {
5726 }
5727
5728 return time_duration::from_turns( static_cast<int>( duration ) );
5729}
auto temperature_flag_to_highest_temperature(temperature_flag temperature) -> units::temperature
Definition: item.cpp:5690
const time_duration INDEFINITELY_LONG_DURATION
The expected duration of the cataclysm.

References itype::comestible, time_duration::from_turns(), get_hourly_rotpoints_at_temp(), calendar::INDEFINITELY_LONG_DURATION, rot, anonymous_namespace{item.cpp}::temperature_flag_to_highest_temperature(), and type.

Referenced by food_info().

◆ mitigate_damage()

void item::mitigate_damage ( damage_unit du) const

Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type.

This will never reduce du.amount below 0.

Definition at line 6373 of file item.cpp.

6374{
6375 const resistances res = resistances( *this );
6376 const float mitigation = res.get_effective_resist( du );
6377 du.amount -= mitigation;
6378 du.amount = std::max( 0.0f, du.amount );
6379}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References damage_unit::amount, and resistances::get_effective_resist().

Referenced by Character::armor_absorb(), and character_funcs::is_bp_immune_to().

◆ mod_charges()

void item::mod_charges ( int  mod)

Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges.

Parameters
modHow many charges should be removed.

Definition at line 9728 of file item.cpp.

9729{
9730 if( has_infinite_charges() ) {
9731 return;
9732 }
9733
9734 if( !count_by_charges() ) {
9735 debugmsg( "Tried to remove %s by charges, but item is not counted by charges.", tname() );
9736 } else if( mod < 0 && charges + mod < 0 ) {
9737 debugmsg( "Tried to remove charges that do not exist, removing maximum available charges instead." );
9738 charges = 0;
9739 } else if( mod > 0 && charges >= INFINITE_CHARGES - mod ) {
9740 charges = INFINITE_CHARGES - 1; // Highly unlikely, but finite charges should not become infinite.
9741 } else {
9742 charges += mod;
9743 }
9744}

References charges, count_by_charges(), debugmsg, has_infinite_charges(), INFINITE_CHARGES, and tname().

Referenced by throw_activity_actor::do_turn(), Character::eat(), fill_with(), player::reduce_charges(), and talk_effect_fun_t::set_u_buy_item().

◆ mod_damage() [1/2]

bool item::mod_damage ( int  qty)

same as other mod_damage, but uses DT_NULL as damage type.

Definition at line 6258 of file item.cpp.

6259{
6260 return mod_damage( qty, DT_NULL );
6261}

References DT_NULL, and mod_damage().

◆ mod_damage() [2/2]

bool item::mod_damage ( int  qty,
damage_type  dt 
)

Apply damage to const itemrained by min_damage and max_damage.

Parameters
qtymaximum amount by which to adjust damage (negative permissible)
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6236 of file item.cpp.

6237{
6238 bool destroy = false;
6239
6240 if( count_by_charges() ) {
6241 charges -= std::min( type->stack_size * qty / itype::damage_scale, charges );
6242 destroy |= charges == 0;
6243 }
6244
6245 if( qty > 0 ) {
6246 on_damage( qty, dt );
6247 }
6248
6249 if( !count_by_charges() ) {
6250 destroy |= damage_ + qty > max_damage();
6251
6252 damage_ = std::max( std::min( damage_ + qty, max_damage() ), min_damage() );
6253 }
6254
6255 return destroy;
6256}
void on_damage(int qty, damage_type dt)
Callback immediately before an item is damaged.
Definition: item.cpp:4569

References charges, count_by_charges(), damage_, itype::damage_scale, max_damage(), min_damage(), on_damage(), itype::stack_size, and type.

Referenced by Character::armor_absorb(), iuse::gun_repair(), inc_damage(), activity_handlers::make_zlave_finish(), mod_damage(), vehicle::mod_hp(), and repair_item_actor::repair().

◆ mod_energy()

units::energy item::mod_energy ( const units::energy qty)

Add or remove energy from a battery.

If adding the specified energy quantity would go over the battery's capacity fill the battery and ignore the remainder. If adding the specified energy quantity would reduce the battery's charge level below 0 do nothing and return how far below 0 it would have gone.

Parameters
qtyenergy quantity to add (can be negative)
Returns
0 valued energy quantity on success

Definition at line 577 of file item.cpp.

578{
579 if( !is_battery() ) {
580 debugmsg( "Tried to set energy of non-battery item" );
581 return 0_J;
582 }
583
584 units::energy val = energy_remaining() + qty;
585 if( val < 0_J ) {
586 return val;
587 } else if( val > type->battery->max_capacity ) {
588 energy = type->battery->max_capacity;
589 } else {
590 energy = val;
591 }
592 return 0_J;
593}

References itype::battery, debugmsg, energy, energy_remaining(), is_battery(), and type.

◆ mod_last_rot_check()

void item::mod_last_rot_check ( time_duration  processing_duration)

This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble.

Parameters
processing_duration

Definition at line 5731 of file item.cpp.

5732{
5733 if( !has_own_flag( "PROCESSING" ) ) {
5734 debugmsg( "mod_last_rot_check called on non smoking item: %s", tname() );
5735 return;
5736 }
5737
5738 // Apply no rot while smoking
5739 last_rot_check += processing_duration;
5740}

References debugmsg, has_own_flag(), last_rot_check, and tname().

◆ mod_rot()

void item::mod_rot ( const time_duration val)
inline

Definition at line 863 of file item.h.

863 {
864 rot += val;
865 }

◆ mutations_from_wearing()

std::vector< trait_id > item::mutations_from_wearing ( const Character guy) const

Definition at line 9083 of file item.cpp.

9084{
9085 if( !is_relic() ) {
9086 return std::vector<trait_id> {};
9087 }
9088 std::vector<trait_id> muts;
9089
9090 for( const enchantment &ench : relic_data->get_enchantments() ) {
9091 for( const trait_id &mut : ench.get_mutations() ) {
9092 // this may not be perfectly accurate due to conditions
9093 muts.push_back( mut );
9094 }
9095 }
9096
9097 for( const trait_id &char_mut : guy.get_mutations() ) {
9098 for( auto iter = muts.begin(); iter != muts.end(); ) {
9099 if( char_mut == *iter ) {
9100 iter = muts.erase( iter );
9101 } else {
9102 ++iter;
9103 }
9104 }
9105 }
9106
9107 return muts;
9108}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References Character::get_mutations(), is_relic(), and relic_data.

Referenced by Character::on_item_takeoff(), and Character::on_item_wear().

◆ needs_processing()

bool item::needs_processing ( ) const

Whether the item should be processed (by calling process).

Definition at line 8936 of file item.cpp.

8937{
8940 is_artifact() || is_food();
8941}
bool needs_processing() const
Whether the item should be processed (by calling process).
Definition: item.cpp:8936
bool is_artifact() const
Definition: item.cpp:6978
static const std::string flag_ETHEREAL_ITEM("ETHEREAL_ITEM")

References active, contents, item_contents::empty(), flag_ETHEREAL_ITEM(), flag_RADIO_ACTIVATION(), item_contents::front(), has_flag(), is_artifact(), is_container(), is_food(), and needs_processing().

Referenced by map::add_item(), vehicle::add_item(), submap::load(), map::make_active(), vehicle::make_active(), needs_processing(), liquid_handler::perform_liquid_transfer(), and Character::process_items().

◆ nname()

std::string item::nname ( const itype_id id,
unsigned int  quantity = 1 
)
static

Returns the translated item name for the item with given id.

The name is in the proper plural form as specified by the quantity parameter. This is roughly equivalent to creating an item instance and calling tname, however this function does not include strings like "(fresh)".

Definition at line 9929 of file item.cpp.

9930{
9931 return id->nname( quantity );
9932}

Referenced by act_vehicle_unload_fuel(), ammo_info(), veh_interact::calc_overview(), camp_car_description(), crafting::can_disassemble(), Character::can_eat(), player::craft_consume_tools(), harvest_list::describe(), veh_interact::display_details(), draw_caravan_items(), spellcasting_callback::draw_spell_info(), farm_action(), activity_handlers::fertilize_plot_do_turn(), final_info(), iexamine::fvat_empty(), plot_options::get_descriptions(), iexamine::get_seed_entries(), plot_options::get_zone_name_suggestion(), repair_item_actor::handle_components(), ammobelt_actor::info(), iexamine::keg(), ma_style_callback::key(), lcmatch_any(), mill_load_food(), iuse::multicooker(), vpart_info::name(), comp_selection< CompType >::nname(), parse_tags(), peek_related_recipe(), activity_handlers::plant_seed_finish(), iexamine::portable_structure(), iexamine::pour_into_keg(), vehicle::print_fuel_indicator(), vehicle::print_part_list(), iexamine::quern_examine(), crafting::query_tool_selection(), avatar_action::reload(), activity_handlers::repair_item_finish(), recipe::result_name(), vehicle::select_engine(), player::select_item_component(), talk_effect_fun_t::set_u_sell_item(), character_funcs::siphon(), smoker_load_food(), iexamine::smoker_options(), vehicle::start_engine(), tname(), tool_comp::to_string(), iexamine::tree_maple(), iexamine::tree_maple_tapped(), try_consume(), unfold_vehicle_iuse::use(), consume_drug_iuse::use(), sew_advanced_actor::use(), and vehicle::use_washing_machine().

◆ on_contents_changed()

void item::on_contents_changed ( )

◆ on_damage()

void item::on_damage ( int  qty,
damage_type  dt 
)

Callback immediately before an item is damaged.

Parameters
qtymaximum damage that will be applied (constrained by max_damage)
dttype of damage (or DT_NULL)

Definition at line 4569 of file item.cpp.

4570{
4571 if( is_corpse() && qty + damage_ >= max_damage() ) {
4573 }
4574}

References damage_, flag_PULPED(), is_corpse(), max_damage(), and set_flag().

Referenced by mod_damage(), and set_damage().

◆ on_drop() [1/2]

bool item::on_drop ( const tripoint pos)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
Returns
true if the item was destroyed during placement.

Definition at line 9994 of file item.cpp.

9995{
9996 return on_drop( pos, get_map() );
9997}
bool on_drop(const tripoint &pos)
Invokes item type's itype::drop_action.
Definition: item.cpp:9994

References get_map(), and on_drop().

Referenced by map::add_item_or_charges(), and on_drop().

◆ on_drop() [2/2]

bool item::on_drop ( const tripoint pos,
map map 
)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
mapA map object associated with that position.
Returns
true if the item was destroyed during placement.

Definition at line 9999 of file item.cpp.

10000{
10001 // dropping liquids, even currently frozen ones, on the ground makes them
10002 // dirty
10003 if( made_of( LIQUID ) && !m.has_flag( flag_LIQUIDCONT, pos ) &&
10004 !has_own_flag( "DIRTY" ) ) {
10005 set_flag( "DIRTY" );
10006 }
10007 avatar &you = get_avatar();
10008 you.flag_encumbrance();
10009 return type->drop_action && type->drop_action.call( you, *this, false, pos );
10010}
void flag_encumbrance()
Flag encumbrance for updating.
Definition: character.cpp:1763
static const std::string flag_LIQUIDCONT("LIQUIDCONT")
use_function drop_action
Action to take BEFORE the item is placed on map.
Definition: itype.h:899
int call(player &, item &, bool, const tripoint &) const
Definition: iuse.cpp:9824

References use_function::call(), itype::drop_action, Character::flag_encumbrance(), flag_LIQUIDCONT(), get_avatar(), map::has_flag(), has_own_flag(), LIQUID, made_of(), set_flag(), and type.

◆ on_pickup()

void item::on_pickup ( Character p)

Callback when a player starts carrying the item.

The item is already in the inventory and is called from there. This is not called when the item is added to the inventory from worn vector or weapon slot. The item is considered already carried.

Definition at line 4538 of file item.cpp.

4539{
4540 // Fake characters are used to determine pickup weight and volume
4541 if( p.is_fake() ) {
4542 return;
4543 }
4544 avatar &you = get_avatar();
4545 // TODO: artifacts currently only work with the player character
4546 if( &p == &you && type->artifact ) {
4547 g->add_artifact_messages( type->artifact->effects_carried );
4548 }
4549 // if game is loaded - don't want ownership assigned during char creation
4550 if( you.getID().is_valid() ) {
4552 }
4553 if( is_bucket_nonempty() ) {
4555 }
4556
4557 p.flag_encumbrance();
4558}
virtual bool is_fake() const
Returns true for non-real Creatures used temporarily; i.e.
Definition: creature.cpp:998
bool is_valid() const
Definition: character_id.h:19
bool spill_contents(const tripoint &pos)
void handle_pickup_ownership(Character &c)
Definition: item.cpp:4498
bool is_bucket_nonempty() const
Definition: item.cpp:6755

References itype::artifact, contents, Character::flag_encumbrance(), g, get_avatar(), Character::getID(), handle_pickup_ownership(), is_bucket_nonempty(), Creature::is_fake(), character_id::is_valid(), Character::pos(), item_contents::spill_contents(), and type.

Referenced by Character::i_add().

◆ on_takeoff()

void item::on_takeoff ( Character p)

Callback when a character takes off an item.

The item is still in the worn items vector but will be removed immediately after the function returns

Definition at line 4417 of file item.cpp.

4418{
4419 p.on_item_takeoff( *this );
4420
4421 if( is_sided() ) {
4423 }
4424
4425 // if power armor, no power_draw and active, shut down.
4426 if( type->can_use( "set_transformed" ) && active ) {
4427 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4428 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4429 if( actor == nullptr ) {
4430 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4431 return;
4432 }
4433 actor->bypass( *p.as_player(), *this, false, p.pos() );
4434 }
4435}
void on_item_takeoff(const item &it)
Called when an item is taken off.
Definition: character.cpp:9874
virtual player * as_player()
Definition: creature.h:122
bool set_side(side s)
Change the side on which the item is worn.
Definition: item.cpp:820
This is a iuse_transform used by items with transform dependencies.
Definition: iuse_actor.h:350
int bypass(player &p, item &it, bool t, const tripoint &pos) const
Hack: Bypasses normal checks to transform an item.
Definition: iuse_actor.cpp:986

References active, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), debugmsg, use_function::get_actor_ptr(), get_use(), is_sided(), Character::on_item_takeoff(), Character::pos(), set_side(), and type.

Referenced by Character::absorb_hit(), Character::i_rem(), and starting_clothes().

◆ on_wear()

void item::on_wear ( Character p)

Callback when a character starts wearing the item.

The item is already in the worn items vector and is called from there.

Definition at line 4319 of file item.cpp.

4320{
4321 if( is_sided() && get_side() == side::BOTH ) {
4322 if( has_flag( flag_SPLINT ) ) {
4324 if( ( covers( bodypart_id( "leg_l" ) ) && p.is_limb_broken( bodypart_id( "leg_r" ) ) &&
4325 !p.worn_with_flag( flag_SPLINT, bodypart_id( "leg_r" ) ) ) ||
4326 ( covers( bodypart_id( "arm_l" ) ) && p.is_limb_broken( bodypart_id( "arm_r" ) ) &&
4327 !p.worn_with_flag( flag_SPLINT, bodypart_id( "arm_r" ) ) ) ) {
4329 }
4330 } else if( has_flag( flag_POWERARMOR_MOD ) ) {
4331 // for power armor mods, wear on side with least mods
4332 std::vector< std::pair< body_part, int > > mod_parts;
4333 body_part bp = num_bp;
4334 bodypart_str_id bpid;
4335 int lhs = 0;
4336 int rhs = 0;
4337 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ) ; ++i ) {
4338 bp = static_cast< body_part >( i );
4339 if( get_covered_body_parts().test( bp ) ) {
4340 mod_parts.emplace_back( bp, 0 );
4341 }
4342 }
4343 for( auto &elem : p.worn ) {
4344 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4345 bpid = convert_bp( mod_part.first );
4346 if( elem.get_covered_body_parts().test( mod_part.first ) &&
4347 elem.has_flag( flag_POWERARMOR_MOD ) ) {
4348 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
4349 mod_part.second++;
4350 continue;
4351 }
4352 mod_part.second++;
4353 }
4354 }
4355 }
4356 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4357 bpid = convert_bp( mod_part.first );
4358 if( bpid->part_side == side::LEFT && mod_part.second > lhs ) {
4359 add_msg( _( "left" ) );
4360 lhs = mod_part.second;
4361 } else if( bpid->part_side == side::RIGHT && mod_part.second > rhs ) {
4362 add_msg( _( "right" ) );
4363 rhs = mod_part.second;
4364 }
4365 }
4366 set_side( ( lhs > rhs ) ? side::RIGHT : side::LEFT );
4367 } else {
4368 // for sided items wear the item on the side which results in least encumbrance
4369 int lhs = 0;
4370 int rhs = 0;
4372 const char_encumbrance_data left_enc = p.get_encumbrance( *this );
4373 for( const body_part bp : all_body_parts ) {
4374 lhs += left_enc.elems[bp].encumbrance;
4375 }
4376
4378 const char_encumbrance_data right_enc = p.get_encumbrance( *this );
4379 for( const body_part bp : all_body_parts ) {
4380 rhs += right_enc.elems[bp].encumbrance;
4381 }
4382
4383 set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
4384 }
4385 }
4386
4387 if( type->can_use( "set_transformed" ) ) {
4388 bool transform = false;
4389 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4390 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4391 if( actor == nullptr ) {
4392 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4393 return;
4394 }
4395 std::string transform_flag = actor->dependencies;
4396 for( const auto &elem : p.worn ) {
4397 if( elem.has_flag( transform_flag ) && elem.active != active ) {
4398 transform = true;
4399 }
4400 }
4401 if( transform && actor->restricted ) {
4402 actor->bypass( *p.as_player(), *this, false, p.pos() );
4403 }
4404 }
4405
4406 // TODO: artifacts currently only work with the player character
4407 if( &p == &get_avatar() && type->artifact ) {
4408 g->add_artifact_messages( type->artifact->effects_worn );
4409 }
4410 // if game is loaded - don't want ownership assigned during char creation
4411 if( get_avatar().getID().is_valid() ) {
4413 }
4414 p.on_item_wear( *this );
4415}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:84
body_part
Definition: bodypart.h:41
@ num_bp
Definition: bodypart.h:54
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3265
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9859
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1265
char_encumbrance_data get_encumbrance() const
Get encumbrance for all body parts.
Definition: character.cpp:3705
Just like the string_id, this is a wrapper for int based identifiers.
Definition: int_id.h:20
bool restricted
Whether the object can only be transformed externally.
Definition: iuse_actor.h:355
std::string dependencies
String defining flag needed on activating item.
Definition: iuse_actor.h:360
static const std::string flag_SPLINT("SPLINT")
void add_msg(std::string msg)
Definition: messages.cpp:910
side part_side
Definition: bodypart.h:128
std::array< encumbrance_data, num_bp > elems

References _, active, add_msg(), all_body_parts, itype::artifact, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), convert_bp(), covers(), debugmsg, set_transformed_iuse::dependencies, char_encumbrance_data::elems, flag_POWERARMOR_MOD(), flag_SPLINT(), g, use_function::get_actor_ptr(), get_avatar(), get_covered_body_parts(), Character::get_encumbrance(), get_side(), get_use(), handle_pickup_ownership(), has_flag(), Character::is_limb_broken(), is_sided(), LEFT, num_bp, Character::on_item_wear(), body_part_type::part_side, Character::pos(), set_transformed_iuse::restricted, RIGHT, set_side(), body_part_set::test(), iexamine::transform(), type, Character::worn, and Character::worn_with_flag().

Referenced by starting_clothes().

◆ on_wield()

void item::on_wield ( player p,
int  mv = 0 
)

Callback when a player starts wielding the item.

The item is already in the weapon slot and is called from there.

Parameters
pplayer that has started wielding item
mvnumber of moves already spent wielding the weapon

Definition at line 4437 of file item.cpp.

4438{
4439 // TODO: artifacts currently only work with the player character
4440 if( &p == &get_avatar() && type->artifact ) {
4441 g->add_artifact_messages( type->artifact->effects_wielded );
4442 }
4443
4444 // weapons with bayonet/bipod or other generic "unhandiness"
4445 if( has_flag( flag_SLOW_WIELD ) && !is_gunmod() ) {
4446 float d = 32.0; // arbitrary linear scaling factor
4447 if( is_gun() ) {
4448 d /= std::max( p.get_skill_level( gun_skill() ), 1 );
4449 } else if( is_melee() ) {
4450 d /= std::max( p.get_skill_level( melee_skill() ), 1 );
4451 }
4452
4453 int penalty = get_var( "volume", volume() / units::legacy_volume_factor ) * d;
4454 p.moves -= penalty;
4455 mv += penalty;
4456 }
4457
4458 // firearms with a folding stock or tool/melee without collapse/retract iuse
4459 if( has_flag( flag_NEEDS_UNFOLD ) && !is_gunmod() ) {
4460 int penalty = 50; // 200-300 for guns, 50-150 for melee, 50 as fallback
4461 if( is_gun() ) {
4462 penalty = std::max( 0, 300 - p.get_skill_level( gun_skill() ) * 10 );
4463 } else if( is_melee() ) {
4464 penalty = std::max( 0, 150 - p.get_skill_level( melee_skill() ) * 10 );
4465 }
4466
4467 p.moves -= penalty;
4468 mv += penalty;
4469 }
4470
4471 std::string msg;
4472
4473 if( mv > 500 ) {
4474 msg = _( "It takes you an extremely long time to wield your %s." );
4475 } else if( mv > 250 ) {
4476 msg = _( "It takes you a very long time to wield your %s." );
4477 } else if( mv > 100 ) {
4478 msg = _( "It takes you a long time to wield your %s." );
4479 } else if( mv > 50 ) {
4480 msg = _( "It takes you several seconds to wield your %s." );
4481 } else {
4482 msg = _( "You wield your %s." );
4483 }
4484 // if game is loaded - don't want ownership assigned during char creation
4485 if( p.getID().is_valid() ) {
4487 }
4488 p.add_msg_if_player( m_neutral, msg, tname() );
4489
4490 if( !p.martial_arts_data->selected_is_none() ) {
4491 p.martial_arts_data->martialart_use_message( p );
4492 }
4493
4494 // Update encumbrance in case we were wearing it
4495 p.flag_encumbrance();
4496}
int moves
Definition: creature.h:582
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:367
@ m_neutral
Definition: enums.h:267
static const std::string flag_NEEDS_UNFOLD("NEEDS_UNFOLD")
static const std::string flag_SLOW_WIELD("SLOW_WIELD")

References _, player::add_msg_if_player(), itype::artifact, Character::flag_encumbrance(), flag_NEEDS_UNFOLD(), flag_SLOW_WIELD(), g, get_avatar(), Character::get_skill_level(), get_var(), Character::getID(), gun_skill(), handle_pickup_ownership(), has_flag(), is_gun(), is_gunmod(), is_melee(), character_id::is_valid(), units::legacy_volume_factor, m_neutral, Character::martial_arts_data, melee_skill(), Creature::moves, tname(), type, and volume().

Referenced by character_funcs::try_wield_contents(), and avatar::wield().

◆ only_made_of()

bool item::only_made_of ( const std::set< material_id > &  mat_idents) const

Check we are made of only the materials (e.g.

false if we have one material not in the set or no materials at all).

Parameters
mat_identsSet of material ids.

Definition at line 6457 of file item.cpp.

6458{
6459 const std::vector<material_id> &mats = made_of();
6460 if( mats.empty() ) {
6461 return false;
6462 }
6463
6464 return std::all_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6465 return mat_idents.count( e );
6466 } );
6467}

References made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ operator<()

bool item::operator< ( const item other) const

Definition at line 7167 of file item.cpp.

7168{
7169 const item_category &cat_a = get_category();
7170 const item_category &cat_b = other.get_category();
7171 if( cat_a != cat_b ) {
7172 return cat_a < cat_b;
7173 } else {
7174 const item *me = is_container() && !contents.empty() ? &contents.front() : this;
7175 const item *rhs = other.is_container() &&
7176 !other.contents.empty() ? &other.contents.front() : &other;
7177
7178 const itype *me_type = me->type;
7179 const itype *rhs_type = rhs->type;
7180 if( !me_type || !rhs_type ) {
7181 return !!me_type;
7182 }
7183
7184 if( me_type->get_id() == rhs_type->get_id() ) {
7185 if( me->is_money() ) {
7186 return me->charges > rhs->charges;
7187 }
7188 return me->charges < rhs->charges;
7189 } else {
7190 std::string n1 = me_type->nname( 1 );
7191 std::string n2 = rhs_type->nname( 1 );
7192 return localized_compare( n1, n2 );
7193 }
7194 }
7195}

References charges, contents, item_contents::empty(), item_contents::front(), get_category(), itype::get_id(), is_container(), is_money(), localized_compare, itype::nname(), other, and type.

◆ operator<=()

bool item::operator<= ( const item other) const
inline

LUA: We need this operator defined for Lua bindings to compile.

Definition at line 1262 of file item.h.

1262 {
1263 return operator<( other ) || operator==( other );
1264 }
bool operator==(const item &rhs) const
LUA: We need this operator defined for Lua bindings to compile.
Definition: item.h:1258
bool operator<(const item &other) const
Definition: item.cpp:7167

References operator<(), coords::operator==(), and other.

◆ operator=() [1/2]

item & item::operator= ( const item )
default

◆ operator=() [2/2]

item & item::operator= ( item &&  )
default

◆ operator==()

bool item::operator== ( const item rhs) const
inline

LUA: We need this operator defined for Lua bindings to compile.

Definition at line 1258 of file item.h.

1258 {
1259 return this == &rhs;
1260 };

◆ price()

int item::price ( bool  practical) const

Returns the monetary value of an item.

If practical is false, returns pre-cataclysm market value, otherwise returns approximate post-cataclysm value.

Definition at line 4948 of file item.cpp.

4949{
4950 int res = 0;
4951
4952 visit_items( [&res, practical]( const item * e ) {
4953 if( e->rotten() ) {
4954 // TODO: Special case things that stay useful when rotten
4955 return VisitResponse::NEXT;
4956 }
4957
4958 int child = units::to_cent( practical ? e->type->price_post : e->type->price );
4959 if( e->damage() > 0 ) {
4960 // maximal damage level is 4, maximal reduction is 40% of the value.
4961 child -= child * static_cast<double>( e->damage_level( 4 ) ) / 10;
4962 }
4963
4964 if( e->count_by_charges() || e->made_of( LIQUID ) ) {
4965 // price from json data is for default-sized stack
4966 child *= e->charges / static_cast<double>( e->type->stack_size );
4967
4968 } else if( e->magazine_integral() && e->ammo_remaining() && e->ammo_data() ) {
4969 // items with integral magazines may contain ammunition which can affect the price
4970 child += item( e->ammo_data(), calendar::turn, e->charges ).price( practical );
4971
4972 } else if( e->is_tool() && e->ammo_types().empty() && e->ammo_capacity() ) {
4973 // if tool has no ammo (e.g. spray can) reduce price proportional to remaining charges
4974 child *= e->ammo_remaining() / static_cast<double>( std::max( e->type->charges_default(), 1 ) );
4975 }
4976
4977 res += child;
4978 return VisitResponse::NEXT;
4979 } );
4980
4981 return res;
4982}
constexpr value_type to_cent(const quantity< value_type, money_in_cent_tag > &v)
Definition: units_money.h:44
units::money price
Value before cataclysm.
Definition: itype.h:956
units::money price_post
Value after cataclysm, dependent upon practical usages.
Definition: itype.h:958

References ammo_capacity(), ammo_data(), ammo_remaining(), ammo_types(), count_by_charges(), damage(), is_tool(), LIQUID, made_of(), magazine_integral(), NEXT, itype::price, itype::price_post, rotten(), units::to_cent(), type, and visitable< item >::visit_items().

Referenced by talk_function::bionic_install(), talk_function::bionic_remove(), defense_game::caravan(), draw_caravan_items(), talk_function::field_harvest(), final_info(), bionic_install_surgeon_preset::get_money_amount(), npc_trading::init_buying(), npc_trading::init_selling(), parse_tags(), talk_effect_fun_t::set_bulk_trade_accept(), npc::shop_restock(), npc::value(), npc::wants_to_buy(), and npc::wants_to_sell().

◆ process() [1/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 9604 of file item.cpp.

9606{
9607 const bool preserves = type->container && type->container->preserves;
9608 const bool seals = type->container && type->container->seals;
9609 std::vector<item *> removed_items;
9610 visit_items( [&]( item * it ) {
9611 if( preserves ) {
9612 // Simulate that the item has already "rotten" up to last_rot_check, but as item::rot
9613 // is not changed, the item is still fresh.
9615 }
9616 if( it->process_internal( carrier, pos, activate, seals, flag, weather_generator ) ) {
9617 removed_items.push_back( it );
9618 }
9619 return VisitResponse::NEXT;
9620 } );
9621 for( item *it : removed_items ) {
9622 if( it != this ) {
9623 remove_item( *it );
9624 }
9625 }
9626 return !removed_items.empty() && std::any_of( removed_items.begin(), removed_items.end(),
9627 [this]( const item * r ) {
9628 return r == this;
9629 } );
9630}
bool process_internal(player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
Definition: item.cpp:9632
item & activate()
Filter converting instance to active state.
Definition: item.cpp:562

References activate(), itype::container, last_rot_check, NEXT, process_internal(), visitable< item >::remove_item(), calendar::turn, type, and visitable< item >::visit_items().

◆ process() [2/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag = temperature_flag::TEMP_NORMAL 
)

This is called once each turn.

It's usually only useful for active items, but can be called for inactive items without problems. It is recursive, and calls process on any contained items.

Parameters
carrierThe player / npc that carries the item. This can be null when the item is not carried by anyone (laying on ground)!
posThe location of the item on the map, same system as player::pos used. If the item is carried, it should be the location of the carrier.
activateWhether the item should be activated (true), or processed as an active item.
Returns
true if the item has been destroyed by the processing. The caller should than delete the item wherever it was stored. Returns false if the item is not destroyed.

Definition at line 9598 of file item.cpp.

9600{
9601 return process( carrier, pos, activate, flag, get_weather() );
9602}
bool process(player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
This is called once each turn.
Definition: item.cpp:9598
weather_manager & get_weather()
Definition: weather.cpp:64

References activate(), get_weather(), and process().

Referenced by map::add_item(), iuse::cable_attach(), drop_or_embed_projectile(), mattack::kamikaze(), process(), vehicle_part::process_contents(), Character::process_items(), and iuse::tow_attach().

◆ process_artifact()

void item::process_artifact ( player carrier,
const tripoint pos 
)

Process and apply artifact effects.

This should be called exactly once each turn, it may modify character stats (like speed, strength, ...), so call it after those have been reset.

Parameters
carrierThe character carrying the artifact, can be null.
posThe location of the artifact (should be the player location if carried).

Definition at line 9068 of file item.cpp.

9069{
9070 if( !is_artifact() ) {
9071 return;
9072 }
9073 // Artifacts are currently only useful for the player character, the messages
9074 // don't consider npcs. Also they are not processed when laying on the ground.
9075 // TODO: change game::process_artifact to work with npcs,
9076 // TODO: consider moving game::process_artifact here.
9077 if( carrier == &get_avatar() ) {
9078 g->process_artifact( *this, *carrier );
9079 }
9080}

References g, get_avatar(), and is_artifact().

Referenced by Character::process_turn().

◆ process_blackpowder_fouling()

bool item::process_blackpowder_fouling ( player carrier)
protected

Definition at line 9587 of file item.cpp.

9588{
9589 if( damage() < max_damage() && one_in( 2000 ) ) {
9591 if( carrier ) {
9592 carrier->add_msg_if_player( m_bad, _( "Your %s rusts due to blackpowder fouling." ), tname() );
9593 }
9594 }
9595 return false;
9596}
@ m_bad
Definition: enums.h:261

References _, player::add_msg_if_player(), damage(), DT_ACID, inc_damage(), m_bad, max_damage(), one_in(), and tname().

Referenced by process_internal().

◆ process_cable()

bool item::process_cable ( player carrier,
const tripoint pos 
)
protected

Definition at line 9369 of file item.cpp.

9370{
9371 if( carrier == nullptr ) {
9372 //reset_cable( carrier );
9373 return false;
9374 }
9375 std::string state = get_var( "state" );
9376 if( state == "solar_pack_link" || state == "solar_pack" ) {
9377 if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
9378 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9379 reset_cable( carrier );
9380 return false;
9381 }
9382 }
9383
9384 static const item_filter used_ups = [&]( const item & itm ) {
9385 return itm.get_var( "cable" ) == "plugged_in";
9386 };
9387
9388 if( state == "UPS" ) {
9389 if( !carrier->has_item( *this ) || !carrier->has_item_with( used_ups ) ) {
9390 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9391 for( item *used : carrier->items_with( used_ups ) ) {
9392 used->erase_var( "cable" );
9393 }
9394 reset_cable( carrier );
9395 return false;
9396 }
9397 }
9398 const std::optional<tripoint> source = get_cable_target( carrier, pos );
9399 if( !source ) {
9400 return false;
9401 }
9402 map &here = get_map();
9403 if( !here.veh_at( *source ) || ( source->z != g->get_levz() && !here.has_zlevels() ) ) {
9404 if( carrier->has_item( *this ) ) {
9405 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9406 }
9407 reset_cable( carrier );
9408 return false;
9409 }
9410
9411 int distance = rl_dist( pos, *source );
9412 int max_charges = type->maximum_charges();
9413 charges = max_charges - distance;
9414
9415 if( charges < 1 ) {
9416 if( carrier->has_item( *this ) ) {
9417 carrier->add_msg_if_player( m_bad, _( "The over-extended cable breaks loose!" ) );
9418 }
9419 reset_cable( carrier );
9420 }
9421
9422 return false;
9423}
void reset_cable(player *p)
Helper to bring a cable back to its initial state.
Definition: item.cpp:9425
std::optional< tripoint > get_cable_target(Character *p, const tripoint &pos) const
Gets the point (vehicle tile) the cable is connected to.
Definition: item.cpp:9349
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:325
std::function< bool(const item &)> item_filter
Definition: game.h:119
int maximum_charges() const
Definition: itype.cpp:123

References _, player::add_msg_if_player(), charges, g, get_cable_target(), get_map(), get_var(), visitable< T >::has_item(), visitable< T >::has_item_with(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), visitable< T >::items_with(), m_bad, itype::maximum_charges(), reset_cable(), rl_dist(), type, and Character::worn_with_flag().

Referenced by process_internal().

◆ process_corpse()

bool item::process_corpse ( player carrier,
const tripoint pos 
)
protected

Definition at line 9126 of file item.cpp.

9127{
9128 // some corpses rez over time
9129 if( corpse == nullptr || damage() >= max_damage() ) {
9130 return false;
9131 }
9132 if( corpse->zombify_into && rotten() ) {
9133 rot -= get_shelf_life();
9135 return false;
9136 }
9137 if( !ready_to_revive( pos ) ) {
9138 return false;
9139 }
9140 if( rng( 0, volume() / units::legacy_volume_factor ) > burnt && g->revive_corpse( pos, *this ) ) {
9141 if( carrier == nullptr ) {
9142 if( get_avatar().sees( pos ) ) {
9143 if( corpse->in_species( ROBOT ) ) {
9144 add_msg( m_warning, _( "A nearby robot has repaired itself and stands up!" ) );
9145 } else {
9146 add_msg( m_warning, _( "A nearby corpse rises and moves towards you!" ) );
9147 }
9148 }
9149 } else {
9150 if( corpse->in_species( ROBOT ) ) {
9151 carrier->add_msg_if_player( m_warning,
9152 _( "Oh dear god, a robot you're carrying has started moving!" ) );
9153 } else {
9154 carrier->add_msg_if_player( m_warning,
9155 _( "Oh dear god, a corpse you're carrying has started moving!" ) );
9156 }
9157 }
9158 // Destroy this corpse item
9159 return true;
9160 }
9161
9162 return false;
9163}
bool ready_to_revive(const tripoint &pos) const
Whether this corpse should revive now.
Definition: item.cpp:5975
@ m_warning
Definition: enums.h:264
static const species_id ROBOT("ROBOT")
mtype_id zombify_into
Definition: mtype.h:333
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, add_msg(), player::add_msg_if_player(), burnt, corpse, damage(), g, get_avatar(), get_shelf_life(), mtype::in_species(), units::legacy_volume_factor, m_warning, max_damage(), ready_to_revive(), rng(), ROBOT, rotten(), volume(), and mtype::zombify_into.

Referenced by process_internal().

◆ process_extinguish()

bool item::process_extinguish ( player carrier,
const tripoint pos 
)
protected

Definition at line 9274 of file item.cpp.

9275{
9276 // checks for water
9277 bool extinguish = false;
9278 bool in_inv = carrier != nullptr && carrier->has_item( *this );
9279 bool submerged = false;
9280 bool precipitation = false;
9281 bool windtoostrong = false;
9282 bool in_veh = carrier != nullptr && carrier->in_vehicle;
9283 int windpower = get_weather().windspeed;
9284 switch( get_weather().weather_id->precip ) {
9286 precipitation = one_in( 100 );
9287 break;
9289 precipitation = one_in( 50 );
9290 break;
9292 precipitation = one_in( 10 );
9293 break;
9294 default:
9295 break;
9296 }
9297 map &here = get_map();
9298 if( in_inv && !in_veh && here.has_flag( flag_DEEP_WATER, pos ) ) {
9299 extinguish = true;
9300 submerged = true;
9301 }
9302 if( ( !in_inv && here.has_flag( flag_LIQUID, pos ) && !here.veh_at( pos ) ) ||
9303 ( precipitation && !g->is_sheltered( pos ) ) ) {
9304 extinguish = true;
9305 }
9306 if( in_inv && windpower > 5 && !g->is_sheltered( pos ) &&
9307 this->has_flag( flag_WIND_EXTINGUISH ) ) {
9308 windtoostrong = true;
9309 extinguish = true;
9310 }
9311 if( !extinguish ||
9312 ( in_inv && precipitation && carrier->primary_weapon().has_flag( flag_RAIN_PROTECT ) ) ) {
9313 return false; //nothing happens
9314 }
9315 if( carrier != nullptr ) {
9316 if( submerged ) {
9317 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by water." ), tname() );
9318 } else if( precipitation ) {
9319 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by precipitation." ),
9320 tname() );
9321 } else if( windtoostrong ) {
9322 carrier->add_msg_if_player( m_neutral, _( "Your %s is blown out by the wind." ),
9323 tname() );
9324 }
9325 }
9326
9327 // cig dies out
9328 if( has_flag( flag_LITCIG ) ) {
9329 if( typeId() == itype_cig_lit ) {
9331 } else if( typeId() == itype_cigar_lit ) {
9333 } else { // joint
9335 }
9336 } else { // transform (lit) items
9337 if( type->tool->revert_to ) {
9338 convert( *type->tool->revert_to );
9339 } else {
9340 type->invoke( carrier != nullptr ? *carrier : get_avatar(), *this, pos, "transform" );
9341 }
9342
9343 }
9344 active = false;
9345 // Item remains
9346 return false;
9347}
bool in_vehicle
Definition: character.h:1571
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:167
static const itype_id itype_cigar_butt("cigar_butt")
static const itype_id itype_joint_roach("joint_roach")
static const itype_id itype_cig_butt("cig_butt")
static const std::string flag_LIQUID("LIQUID")
static const std::string flag_DEEP_WATER("DEEP_WATER")
static const itype_id itype_cigar_lit("cigar_lit")
static const std::string flag_WIND_EXTINGUISH("WIND_EXTINGUISH")
static const std::string flag_RAIN_PROTECT("RAIN_PROTECT")
static const itype_id itype_cig_lit("cig_lit")
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:180

References _, active, player::add_msg_if_player(), convert(), flag_DEEP_WATER(), flag_LIQUID(), flag_LITCIG(), flag_RAIN_PROTECT(), flag_WIND_EXTINGUISH(), g, get_avatar(), get_map(), get_weather(), has_flag(), visitable< T >::has_item(), heavy, anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), Character::in_vehicle, itype::invoke(), itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, light, m_neutral, one_in(), Character::primary_weapon(), tname(), itype::tool, type, typeId(), very_light, and weather_manager::windspeed.

Referenced by process_internal(), and process_litcig().

◆ process_fake_mill()

bool item::process_fake_mill ( player carrier,
const tripoint pos 
)
protected

Definition at line 9165 of file item.cpp.

9166{
9167 map &here = get_map();
9168 if( here.furn( pos ) != furn_str_id( "f_wind_mill_active" ) &&
9169 here.furn( pos ) != furn_str_id( "f_water_mill_active" ) ) {
9170 item_counter = 0;
9171 return true; //destroy fake mill
9172 }
9173 if( age() >= 6_hours || item_counter == 0 ) {
9175 birthday() ); //activate effects when timers goes to zero
9176 return true; //destroy fake mill item
9177 }
9178
9179 return false;
9180}
void mill_finalize(player &, const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5409

References age(), birthday(), get_avatar(), get_map(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, and iexamine::mill_finalize().

Referenced by process_internal().

◆ process_fake_smoke()

bool item::process_fake_smoke ( player carrier,
const tripoint pos 
)
protected

Definition at line 9182 of file item.cpp.

9183{
9184 map &here = get_map();
9185 if( here.furn( pos ) != furn_str_id( "f_smoking_rack_active" ) &&
9186 here.furn( pos ) != furn_str_id( "f_metal_smoking_rack_active" ) ) {
9187 item_counter = 0;
9188 return true; //destroy fake smoke
9189 }
9190
9191 if( age() >= 6_hours || item_counter == 0 ) {
9192 iexamine::on_smoke_out( pos, birthday() ); //activate effects when timers goes to zero
9193 return true; //destroy fake smoke when it 'burns out'
9194 }
9195
9196 return false;
9197}
void on_smoke_out(const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5725

References age(), birthday(), get_map(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, and iexamine::on_smoke_out().

Referenced by process_internal().

◆ process_internal()

bool item::process_internal ( player carrier,
const tripoint pos,
bool  activate,
bool  seals,
temperature_flag  flag,
const weather_manager weather_generator 
)
private

Definition at line 9632 of file item.cpp.

9635{
9636 if( has_flag( flag_ETHEREAL_ITEM ) ) {
9637 if( !has_var( "ethereal" ) ) {
9638 return true;
9639 }
9640 set_var( "ethereal", std::stoi( get_var( "ethereal" ) ) - 1 );
9641 const bool processed = std::stoi( get_var( "ethereal" ) ) <= 0;
9642 if( processed && carrier != nullptr ) {
9643 carrier->add_msg_if_player( _( "Your %s disappears!" ), tname() );
9644 }
9645 return processed;
9646 }
9647
9648 if( faults.count( fault_gun_blackpowder ) ) {
9649 return process_blackpowder_fouling( carrier );
9650 }
9651
9652 avatar &you = get_avatar();
9653 if( activate ) {
9654 return type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9655 }
9656 // How this works: it checks what kind of processing has to be done
9657 // (e.g. for food, for drying towels, lit cigars), and if that matches,
9658 // call the processing function. If that function returns true, the item
9659 // has been destroyed by the processing, so no further processing has to be
9660 // done.
9661 // Otherwise processing continues. This allows items that are processed as
9662 // food and as litcig and as ...
9663
9664 // Remaining stuff is only done for active items.
9665 if( !active ) {
9666 return false;
9667 }
9668
9669 if( !is_food() && item_counter > 0 ) {
9670 item_counter--;
9671 }
9672
9673 if( item_counter == 0 && type->countdown_action ) {
9674 type->countdown_action.call( carrier ? *carrier : you, *this, false, pos );
9675 if( type->countdown_destroy ) {
9676 return true;
9677 }
9678 }
9679
9680 map &here = get_map();
9681 for( const emit_id &e : type->emits ) {
9682 here.emit_field( pos, e );
9683 }
9684
9685 if( has_flag( flag_FAKE_SMOKE ) && process_fake_smoke( carrier, pos ) ) {
9686 return true;
9687 }
9688 if( has_flag( flag_FAKE_MILL ) && process_fake_mill( carrier, pos ) ) {
9689 return true;
9690 }
9691 if( is_corpse() && process_corpse( carrier, pos ) ) {
9692 return true;
9693 }
9694 if( has_flag( flag_WET ) && process_wet( carrier, pos ) ) {
9695 // Drying items are never destroyed, but we want to exit so they don't get processed as tools.
9696 return false;
9697 }
9698 if( has_flag( flag_LITCIG ) && process_litcig( carrier, pos ) ) {
9699 return true;
9700 }
9702 process_extinguish( carrier, pos ) ) {
9703 return false;
9704 }
9705 if( has_flag( flag_CABLE_SPOOL ) ) {
9706 // DO NOT process this as a tool! It really isn't!
9707 return process_cable( carrier, pos );
9708 }
9709 if( has_flag( flag_IS_UPS ) ) {
9710 // DO NOT process this as a tool! It really isn't!
9711 return process_UPS( carrier, pos );
9712 }
9713 if( is_tool() ) {
9714 return process_tool( carrier, pos );
9715 }
9716 // All foods that go bad have temperature
9717 if( ( is_food() || is_corpse() ) &&
9718 process_rot( seals, pos, carrier, flag, weather_generator ) ) {
9719 if( is_comestible() ) {
9720 here.rotten_item_spawn( *this, pos );
9721 }
9722 return true;
9723 }
9724
9725 return false;
9726}
bool process_fake_mill(player *carrier, const tripoint &pos)
Definition: item.cpp:9165
bool process_UPS(player *carrier, const tripoint &pos)
Definition: item.cpp:9442
bool process_corpse(player *carrier, const tripoint &pos)
Definition: item.cpp:9126
bool process_wet(player *carrier, const tripoint &pos)
Definition: item.cpp:9460
bool process_blackpowder_fouling(player *carrier)
Definition: item.cpp:9587
bool process_litcig(player *carrier, const tripoint &pos)
Definition: item.cpp:9199
bool process_extinguish(player *carrier, const tripoint &pos)
Definition: item.cpp:9274
bool process_fake_smoke(player *carrier, const tripoint &pos)
Definition: item.cpp:9182
bool process_tool(player *carrier, const tripoint &pos)
Definition: item.cpp:9473
bool process_cable(player *carrier, const tripoint &pos)
Definition: item.cpp:9369
static const std::string flag_WATER_EXTINGUISH("WATER_EXTINGUISH")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const fault_id fault_gun_blackpowder("fault_gun_blackpowder")
static const std::string flag_IS_UPS("IS_UPS")
static const std::string flag_FAKE_MILL("FAKE_MILL")
static const std::string flag_FAKE_SMOKE("FAKE_SMOKE")
use_function countdown_action
Action to take when countdown expires.
Definition: itype.h:927
bool countdown_destroy
Is item destroyed after the countdown action is run?
Definition: itype.h:921
std::set< emit_id > emits
Fields to emit when item is in active state.
Definition: itype.h:902

References _, activate(), active, player::add_msg_if_player(), use_function::call(), itype::countdown_action, itype::countdown_destroy, itype::emits, fault_gun_blackpowder, faults, flag_CABLE_SPOOL(), flag_ETHEREAL_ITEM(), flag_FAKE_MILL(), flag_FAKE_SMOKE(), flag_IS_UPS(), flag_LITCIG(), flag_WATER_EXTINGUISH(), flag_WET(), flag_WIND_EXTINGUISH(), get_avatar(), get_map(), get_var(), has_flag(), has_var(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), itype::invoke(), is_comestible(), is_corpse(), is_food(), is_tool(), item_counter, process_blackpowder_fouling(), process_cable(), process_corpse(), process_extinguish(), process_fake_mill(), process_fake_smoke(), process_litcig(), process_rot(), process_tool(), process_UPS(), process_wet(), set_var(), tname(), and type.

Referenced by process().

◆ process_litcig()

bool item::process_litcig ( player carrier,
const tripoint pos 
)
protected

Definition at line 9199 of file item.cpp.

9200{
9201 if( !one_in( 10 ) ) {
9202 return false;
9203 }
9204 process_extinguish( carrier, pos );
9205 // process_extinguish might have extinguished the item already
9206 if( !active ) {
9207 return false;
9208 }
9209 map &here = get_map();
9210 // if carried by someone:
9211 if( carrier != nullptr ) {
9212 time_duration duration = 15_seconds;
9213 if( carrier->has_trait( trait_TOLERANCE ) ) {
9214 duration = 7_seconds;
9215 } else if( carrier->has_trait( trait_LIGHTWEIGHT ) ) {
9216 duration = 30_seconds;
9217 }
9218 carrier->add_msg_if_player( m_neutral, _( "You take a puff of your %s." ), tname() );
9219 if( has_flag( flag_TOBACCO ) ) {
9220 carrier->add_effect( effect_cig, duration );
9221 } else {
9222 carrier->add_effect( effect_weed_high, duration / 2 );
9223 }
9224 carrier->moves -= 15;
9225
9226 if( ( carrier->has_effect( effect_shakes ) && one_in( 10 ) ) ) {
9227 carrier->add_msg_if_player( m_bad, _( "Your shaking hand causes you to drop your %s." ),
9228 tname() );
9229 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9230 return true; // removes the item that has just been added to the map
9231 }
9232
9233 if( carrier->has_effect( effect_sleep ) ) {
9234 carrier->add_msg_if_player( m_bad, _( "You fall asleep and drop your %s." ),
9235 tname() );
9236 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9237 return true; // removes the item that has just been added to the map
9238 }
9239 } else {
9240 // If not carried by someone, but laying on the ground:
9241 if( item_counter % 5 == 0 ) {
9242 // lit cigarette can start fires
9243 if( here.flammable_items_at( pos ) ||
9244 here.has_flag( flag_FLAMMABLE, pos ) ||
9245 here.has_flag( flag_FLAMMABLE_ASH, pos ) ) {
9246 here.add_field( pos, fd_fire, 1 );
9247 }
9248 }
9249 }
9250
9251 // cig dies out
9252 if( item_counter == 0 ) {
9253 if( carrier != nullptr ) {
9254 carrier->add_msg_if_player( m_neutral, _( "You finish your %s." ), tname() );
9255 }
9256 if( typeId() == itype_cig_lit ) {
9258 } else if( typeId() == itype_cigar_lit ) {
9260 } else { // joint
9262 if( carrier != nullptr ) {
9263 carrier->add_effect( effect_weed_high, 1_minutes ); // one last puff
9264 here.add_field( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), fd_weedsmoke, 2 );
9265 weed_msg( *carrier );
9266 }
9267 }
9268 active = false;
9269 }
9270 // Item remains
9271 return false;
9272}
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:1008
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1207
void weed_msg(player &p)
Handles the large variety of weed messages.
Definition: effect.cpp:78
field_type_id fd_fire
Definition: field_type.cpp:345
field_type_id fd_weedsmoke
Definition: field_type.cpp:368
static const efftype_id effect_weed_high("weed_high")
static const trait_id trait_TOLERANCE("TOLERANCE")
static const trait_id trait_LIGHTWEIGHT("LIGHTWEIGHT")
static const std::string flag_FLAMMABLE("FLAMMABLE")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static const std::string flag_FLAMMABLE_ASH("FLAMMABLE_ASH")
static const std::string flag_TOBACCO("TOBACCO")
static const efftype_id effect_shakes("shakes")
Definition: point.h:35

References _, active, Creature::add_effect(), player::add_msg_if_player(), convert(), effect_cig, effect_shakes, effect_sleep, effect_weed_high, fd_fire, fd_weedsmoke, flag_FLAMMABLE(), flag_FLAMMABLE_ASH(), flag_TOBACCO(), get_map(), Creature::has_effect(), has_flag(), Character::has_trait(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, m_bad, m_neutral, Creature::moves, one_in(), process_extinguish(), rng(), tname(), trait_LIGHTWEIGHT, trait_TOLERANCE, typeId(), and weed_msg().

Referenced by process_internal().

◆ process_relic()

void item::process_relic ( Character carrier)

Definition at line 9110 of file item.cpp.

9111{
9112 if( !is_relic() ) {
9113 return;
9114 }
9115 std::vector<enchantment> active_enchantments;
9116
9117 for( const enchantment &ench : get_enchantments() ) {
9118 if( ench.is_active( carrier, *this ) ) {
9119 active_enchantments.emplace_back( ench );
9120 }
9121 }
9122
9123 relic_funcs::process_recharge( *this, carrier );
9124}
void process_recharge(item &itm, Character &carrier)
Definition: relic.cpp:449

References get_enchantments(), is_relic(), and relic_funcs::process_recharge().

Referenced by Character::process_turn().

◆ process_rot() [1/2]

bool item::process_rot ( bool  seals,
const tripoint pos,
player carrier,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 8980 of file item.cpp.

8983{
8984 const time_point now = calendar::turn;
8985
8986 // if player debug menu'd the time backward it breaks stuff, just reset the
8987 // last_temp_check and last_rot_check in this case
8988 if( now - last_rot_check < 0_turns ) {
8989 last_rot_check = now;
8990 return false;
8991 }
8992
8993 // process rot at most once every 100_turns (10 min)
8994 // note we're also gated by item::processing_speed
8995 constexpr time_duration smallest_interval = 10_minutes;
8996
8997 units::temperature temp = units::from_fahrenheit( weather.get_temperature( pos ) );
8998 temp = clip_by_temperature_flag( temp, flag );
8999
9002
9003 if( now - time > 1_hours ) {
9004 // This code is for items that were left out of reality bubble for long time
9005
9006 const weather_generator &wgen = weather.get_cur_weather_gen();
9007 const unsigned int seed = g->get_seed();
9008 // It's a modifier, so we need to subtract 0_f
9009 units::temperature local_mod = units::from_fahrenheit( g->new_game
9010 ? 0
9011 : get_map().get_temperature( pos ) ) - 0_f;
9012
9013 // Process the past of this item since the last time it was processed
9014 while( now - time > 1_hours ) {
9015 // Get the environment temperature
9016 time_duration time_delta = std::min( 1_hours, now - 1_hours - time );
9017 time += time_delta;
9018
9019 //Use weather if above ground, use map temp if below
9020 units::temperature env_temperature_raw;
9021 if( pos.z >= 0 ) {
9022 tripoint_abs_ms location = tripoint_abs_ms( get_map().getabs( pos ) );
9023 units::temperature weather_temperature = wgen.get_weather_temperature( location, time,
9025 env_temperature_raw = weather_temperature + local_mod;
9026 } else {
9027 env_temperature_raw = temperatures::annual_average + local_mod;
9028 }
9029
9030 units::temperature env_temperature_clipped = clip_by_temperature_flag( env_temperature_raw, flag );
9031
9032 // Calculate item rot
9033 rot += calc_rot( time, env_temperature_clipped );
9035
9036 if( has_rotten_away() && carrier == nullptr && !seals ) {
9037 // No need to track item that will be gone
9038 return true;
9039 }
9040 }
9041 }
9042
9043 // Remaining <1 h from above
9044 // and items that are held near the player
9045 if( now - time > smallest_interval ) {
9046 rot += calc_rot( now, temp );
9047 last_rot_check = now;
9048
9049 return has_rotten_away() && carrier == nullptr && !seals;
9050 }
9051 // If we're still here, mark how cold it is so we can apply tagtext to items
9052 // FIXME: this might cause issues with performance, move the comparision
9053 // directly to item::tname once #2250 lands
9054 if( temp <= temperatures::freezing ) {
9057 } else if( temp <= temperatures::root_cellar ) {
9060 } else {
9063 }
9064
9065 return false;
9066}
auto calc_rot(time_point time, const units::temperature temp) const -> time_duration
Returns rot of the item since last rot calculation.
Definition: item.cpp:5657
bool has_rotten_away() const
Whether the item has enough rot that it should get removed.
Definition: item.cpp:8796
A point in the game time.
Definition: calendar.h:431
units::temperature get_weather_temperature(const tripoint_abs_ms &, const time_point &, const calendar_config &calendar_config, unsigned) const
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
static units::temperature clip_by_temperature_flag(units::temperature temperature, temperature_flag flag)
Definition: item.cpp:8957
static const std::string flag_VERY_COLD("VERY_COLD")
static const std::string flag_COLD("COLD")
calendar_config config
int seed(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:5972
constexpr units::temperature annual_average
Average annual temperature used for climate, weather and temperature calculation.
constexpr units::temperature freezing
constexpr units::temperature root_cellar
constexpr quantity< value_type, temperature_in_millidegree_celsius_tag > from_fahrenheit(const value_type v)
int z
Definition: point.h:138

References temperatures::annual_average, calc_rot(), clip_by_temperature_flag(), calendar::config, flag_COLD(), flag_VERY_COLD(), temperatures::freezing, units::from_fahrenheit(), g, get_map(), weather_generator::get_weather_temperature(), has_rotten_away(), last_rot_check, temperatures::root_cellar, iuse::seed(), set_flag(), time, calendar::turn, unset_flag(), and tripoint::z.

◆ process_rot() [2/2]

bool item::process_rot ( const tripoint pos)

Update temperature for things like food Update rot for things that perish All items that rot also have temperature.

Parameters
sealsWether the item is in sealed container
posThe current position
carrierThe current carrier
flagto specify special temperature situations
weather_generatorweather manager, mostly for testing
Returns
true if the item is fully rotten and is ready to be removed

Definition at line 8952 of file item.cpp.

8953{
8954 return process_rot( false, pos, nullptr, temperature_flag::TEMP_NORMAL, get_weather() );
8955}

References get_weather(), process_rot(), and TEMP_NORMAL.

Referenced by actualize_rot(), process_internal(), and process_rot().

◆ process_tool()

bool item::process_tool ( player carrier,
const tripoint pos 
)
protected

Definition at line 9473 of file item.cpp.

9474{
9475 avatar &you = get_avatar();
9476 // items with iuse set_transformed which are restricted turn off if not attached to their dependency.
9477 if( type->can_use( "set_transformed" ) ) {
9478 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9479 ( this->get_use( "set_transformed" )->get_actor_ptr() );
9480 if( actor == nullptr ) {
9481 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9482 return false;
9483 }
9484 if( actor->restricted ) {
9485 if( !carrier ) {
9486 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9487 return false;
9488 } else {
9489 bool active = false;
9490 std::string transform_flag = actor->dependencies;
9491 for( const auto &elem : carrier->worn ) {
9492 if( elem.active && elem.has_flag( transform_flag ) ) {
9493 active = true;
9494 break;
9495 }
9496 }
9497 if( !active ) {
9498 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9499 return false;
9500 }
9501 }
9502 }
9503 }
9504
9505 int energy = 0;
9506 if( type->tool->turns_per_charge > 0 &&
9507 to_turn<int>( calendar::turn ) % type->tool->turns_per_charge == 0 ) {
9508 energy = std::max( ammo_required(), 1 );
9509
9510 } else if( type->tool->power_draw > 0 ) {
9511 // power_draw in mW / 1000000 to give kJ (battery unit) per second
9512 energy = type->tool->power_draw / 1000000;
9513 // energy_bat remainder results in chance at additional charge/discharge
9514 energy += x_in_y( type->tool->power_draw % 1000000, 1000000 ) ? 1 : 0;
9515 }
9516 energy -= ammo_consume( energy, pos );
9517
9518 // for power armor pieces, try to use power armor interface first.
9519 if( carrier && is_power_armor() && character_funcs::can_interface_armor( *carrier ) ) {
9520 if( carrier->use_charges_if_avail( itype_bio_armor, energy ) ) {
9521 energy = 0;
9522 }
9523 }
9524
9525 // for items in player possession if insufficient charges within tool try UPS
9526 if( carrier && ( has_flag( flag_USE_UPS ) ) ) {
9527 if( carrier->use_charges_if_avail( itype_UPS, energy ) ) {
9528 energy = 0;
9529 }
9530 }
9531
9532 // if insufficient available charges shutdown the tool
9533 if( energy > 0 ) {
9534 if( carrier ) {
9535 if( is_power_armor() ) {
9536 if( has_flag( flag_USE_UPS ) ) {
9537 carrier->add_msg_if_player( m_info, _( "You need a UPS or Bionic Power Interface to run the %s!" ),
9538 tname() );
9539 } else {
9540 carrier->add_msg_if_player( m_info, _( "You need a Bionic Power Interface to run the %s!" ),
9541 tname() );
9542 }
9543 } else if( has_flag( flag_USE_UPS ) ) {
9544 carrier->add_msg_if_player( m_info, _( "You need a UPS to run the %s!" ), tname() );
9545 }
9546 }
9547 if( carrier && type->can_use( "set_transform" ) ) {
9548 const set_transform_iuse *actor = dynamic_cast<const set_transform_iuse *>
9549 ( this->get_use( "set_transform" )->get_actor_ptr() );
9550 if( actor == nullptr ) {
9551 debugmsg( "iuse_actor type descriptor and actual type mismatch." );
9552 return false;
9553 }
9554 std::string transformed_flag = actor->flag;
9555 for( auto &elem : carrier->worn ) {
9556 if( elem.active && elem.has_flag( transformed_flag ) ) {
9557 if( !elem.type->can_use( "set_transformed" ) ) {
9558 debugmsg( "Expected set_transformed function" );
9559 return false;
9560 }
9561 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9562 ( elem.get_use( "set_transformed" )->get_actor_ptr() );
9563 if( actor == nullptr ) {
9564 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9565 return false;
9566 }
9567 actor->bypass( *carrier, elem, false, pos );
9568 }
9569 }
9570 }
9571
9572 // invoking the object can convert the item to another type
9573 const bool had_revert_to = type->tool->revert_to.has_value();
9574 type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9575 if( had_revert_to ) {
9576 deactivate( carrier );
9577 return false;
9578 } else {
9579 return true;
9580 }
9581 }
9582
9583 type->tick( carrier != nullptr ? *carrier : you, *this, pos );
9584 return false;
9585}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9659
item & deactivate(const Character *ch=nullptr, bool alert=true)
Filter converting this instance to the inactive type If the item is either inactive or cannot be deac...
Definition: item.cpp:545
This is a iuse_transform that changes a set of items with a specific flag.
Definition: iuse_actor.h:318
std::string flag
Flag string so we know what the heck we're transforming.
Definition: iuse_actor.h:328
static const itype_id itype_UPS("UPS")
static const itype_id itype_bio_armor("bio_armor")
bool can_interface_armor(const Character &who)
Check whether character has an active bionic capable of interfacing with power armor.
void tick(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:172

References _, active, player::add_msg_if_player(), ammo_consume(), ammo_required(), set_transformed_iuse::bypass(), character_funcs::can_interface_armor(), itype::can_use(), deactivate(), debugmsg, set_transformed_iuse::dependencies, energy, set_transform_iuse::flag, flag_USE_UPS(), use_function::get_actor_ptr(), get_avatar(), get_use(), has_flag(), itype::invoke(), is_power_armor(), itype_bio_armor, itype_UPS, m_info, set_transformed_iuse::restricted, itype::tick(), tname(), itype::tool, calendar::turn, type, Character::use_charges_if_avail(), Character::worn, and x_in_y().

Referenced by process_internal().

◆ process_UPS()

bool item::process_UPS ( player carrier,
const tripoint pos 
)
protected

Definition at line 9442 of file item.cpp.

9443{
9444 if( carrier == nullptr ) {
9445 erase_var( "cable" );
9446 active = false;
9447 return false;
9448 }
9449 bool has_connected_cable = carrier->has_item_with( []( const item & it ) {
9450 return it.active && it.has_flag( flag_CABLE_SPOOL ) && ( it.get_var( "state" ) == "UPS_link" ||
9451 it.get_var( "state" ) == "UPS" );
9452 } );
9453 if( !has_connected_cable ) {
9454 erase_var( "cable" );
9455 active = false;
9456 }
9457 return false;
9458}

References active, erase_var(), flag_CABLE_SPOOL(), get_var(), has_flag(), and visitable< T >::has_item_with().

Referenced by process_internal().

◆ process_wet()

bool item::process_wet ( player carrier,
const tripoint pos 
)
protected

Definition at line 9460 of file item.cpp.

9461{
9462 if( item_counter == 0 ) {
9463 if( is_tool() && type->tool->revert_to ) {
9464 convert( *type->tool->revert_to );
9465 }
9466 unset_flag( "WET" );
9467 active = false;
9468 }
9469 // Always return true so our caller will bail out instead of processing us as a tool.
9470 return true;
9471}

References active, convert(), is_tool(), item_counter, itype::tool, type, and unset_flag().

Referenced by process_internal().

◆ processing_speed()

int item::processing_speed ( ) const

The rate at which an item should be processed, in number of turns between updates.

Definition at line 8943 of file item.cpp.

8944{
8945 if( is_corpse() || is_food() || is_food_container() ) {
8946 return to_turns<int>( 10_minutes );
8947 }
8948 // Unless otherwise indicated, update every turn.
8949 return 1;
8950}

References is_corpse(), is_food(), and is_food_container().

Referenced by active_item_cache::add().

◆ put_in()

◆ qualities_info()

void item::qualities_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3250 of file item.cpp.

3252{
3253 auto name_quality = [&info]( const std::pair<quality_id, int> &q ) {
3254 std::string str;
3255 if( q.first == qual_JACK || q.first == qual_LIFT ) {
3256 str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
3257 "is rated at <info>%3$d</info> %4$s" ),
3258 q.second, q.first.obj().name,
3259 static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
3260 weight_units() );
3261 } else {
3262 str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
3263 q.second, q.first.obj().name );
3264 }
3265 info.emplace_back( "QUALITIES", "", str );
3266 };
3267
3268 if( parts->test( iteminfo_parts::QUALITIES ) ) {
3270 for( const std::pair<const quality_id, int> q : sorted_lex( type->qualities ) ) {
3271 name_quality( q );
3272 }
3273 }
3274
3276 contents.has_any_with( []( const item & e ) {
3277 return !e.type->qualities.empty();
3278 } ) ) {
3279
3280 info.emplace_back( "QUALITIES", "", _( "Contains items with qualities:" ) );
3281 std::map<quality_id, int, quality_id::LexCmp> most_quality;
3282 for( const item *e : contents.all_items_top() ) {
3283 for( const std::pair<const quality_id, int> &q : e->type->qualities ) {
3284 auto emplace_result = most_quality.emplace( q );
3285 if( !emplace_result.second &&
3286 most_quality.at( emplace_result.first->first ) < q.second ) {
3287 most_quality[ q.first ] = q.second;
3288 }
3289 }
3290 }
3291 for( const std::pair<const quality_id, int> &q : most_quality ) {
3292 name_quality( q );
3293 }
3294 }
3295}
bool has_any_with(const std::function< bool(const item &)> &filter) const
static constexpr units::mass TOOL_LIFT_FACTOR
static const quality_id qual_JACK("JACK")
static const quality_id qual_LIFT("LIFT")

References _, item_contents::all_items_top(), contents, convert_weight(), item_contents::has_any_with(), info(), insert_separation_line(), qual_JACK, qual_LIFT, QUALITIES, itype::qualities, QUALITIES_CONTAINED, sorted_lex(), string_format(), iteminfo_query::test(), TOOL_LIFT_FACTOR, type, and weight_units().

Referenced by info().

◆ quality_of()

const std::map< quality_id, int > & item::quality_of ( ) const

The ids of all the qualities this contains.

Definition at line 6431 of file item.cpp.

6432{
6433 return type->qualities;
6434}

References itype::qualities, and type.

◆ reach_range()

int item::reach_range ( const Character guy) const

Max range of melee attack this weapon can be used for.

Accounts for character's abilities and installed gun mods. Guaranteed to be at least 1

Definition at line 5292 of file item.cpp.

5293{
5294 int res = 1;
5295
5296 if( has_flag( flag_REACH_ATTACK ) ) {
5297 res = has_flag( flag_REACH3 ) ? 3 : 2;
5298 }
5299
5300 // for guns consider any attached gunmods
5301 if( is_gun() && !is_gunmod() ) {
5302 for( const std::pair<const gun_mode_id, gun_mode> &m : gun_all_modes() ) {
5303 if( guy.is_npc() && m.second.flags.count( "NPC_AVOID" ) ) {
5304 continue;
5305 }
5306 if( m.second.melee() ) {
5307 res = std::max( res, m.second.qty );
5308 }
5309 }
5310 }
5311
5312 return std::max( 1, res );
5313}
virtual bool is_npc() const
Definition: creature.h:98

References flag_REACH3(), flag_REACH_ATTACK(), gun_all_modes(), has_flag(), is_gun(), is_gunmod(), and Creature::is_npc().

Referenced by avatar_action::autoattack(), fire(), npc::invalidate_range_cache(), Character::melee_attack(), npc_ai::melee_value(), npc::method_of_attack(), and target_handler::mode_reach().

◆ ready_to_revive()

bool item::ready_to_revive ( const tripoint pos) const

Whether this corpse should revive now.

Note that this function includes some randomness, the return value can differ on successive calls.

Parameters
posThe location of the item (see REVIVE_SPECIAL flag).

Definition at line 5975 of file item.cpp.

5976{
5977 if( !can_revive() ) {
5978 return false;
5979 }
5980 if( get_map().veh_at( pos ) ) {
5981 return false;
5982 }
5983 if( !calendar::once_every( 1_seconds ) ) {
5984 return false;
5985 }
5986 int age_in_hours = to_hours<int>( age() );
5987 age_in_hours -= static_cast<int>( static_cast<float>( burnt ) / ( volume() / 250_ml ) );
5988 if( damage_level( 4 ) > 0 ) {
5989 age_in_hours /= ( damage_level( 4 ) + 1 );
5990 }
5991 int rez_factor = 48 - age_in_hours;
5992 if( age_in_hours > 6 && ( rez_factor <= 0 || one_in( rez_factor ) ) ) {
5993 // If we're a special revival zombie, wait to get up until the player is nearby.
5994 const bool isReviveSpecial = has_flag( flag_REVIVE_SPECIAL );
5995 if( isReviveSpecial ) {
5996 const int distance = rl_dist( pos, get_player_character().pos() );
5997 if( distance > 3 ) {
5998 return false;
5999 }
6000 if( !one_in( distance + 1 ) ) {
6001 return false;
6002 }
6003 }
6004
6005 return true;
6006 }
6007 return false;
6008}
static const std::string flag_REVIVE_SPECIAL("REVIVE_SPECIAL")
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490

References age(), burnt, can_revive(), damage_level(), flag_REVIVE_SPECIAL(), get_map(), get_player_character(), has_flag(), calendar::once_every(), one_in(), rl_dist(), and volume().

Referenced by process_corpse().

◆ reinforceable()

bool item::reinforceable ( ) const

Whether the item can be repaired beyond normal health.

Definition at line 6509 of file item.cpp.

6510{
6511 if( is_null() || has_flag( flag_NO_REPAIR ) ) {
6512 return false;
6513 }
6514
6515 // If a material is reinforceable, so are we
6516 const std::vector<const material_type *> &mats = made_of_types();
6517 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6518 return mt->reinforces();
6519 } );
6520}
static const std::string flag_NO_REPAIR("NO_REPAIR")

References flag_NO_REPAIR(), has_flag(), is_null(), and made_of_types().

Referenced by repair_item_actor::can_repair_target(), repair_item_actor::repair(), and repair_info().

◆ release_monster()

bool item::release_monster ( const tripoint target,
int  radius = 0 
)

Definition at line 9197 of file iuse.cpp.

9198{
9199 shared_ptr_fast<monster> new_monster = make_shared_fast<monster>();
9200 try {
9201 ::deserialize( *new_monster, get_var( "contained_json", "" ) );
9202 } catch( const std::exception &e ) {
9203 debugmsg( _( "Error restoring monster: %s" ), e.what() );
9204 return false;
9205 }
9206 if( !g->place_critter_around( new_monster, target, radius ) ) {
9207 return false;
9208 }
9209 erase_var( "contained_name" );
9210 erase_var( "contained_json" );
9211 erase_var( "name" );
9212 erase_var( "weight" );
9213 return true;
9214}
void deserialize(JsonIn &jsin)
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, debugmsg, deserialize(), erase_var(), g, and get_var().

Referenced by iuse::capture_monster_act(), and DefaultRemovePartHandler::spawn_animal_from_part().

◆ reload()

bool item::reload ( player u,
item_location  loc,
int  qty 
)

Reload item using ammo from location returning true if successful.

Parameters
uPlayer doing the reloading
locLocation of ammo to be reloaded
qtycaps reloading to this (or fewer) units

Definition at line 8112 of file item.cpp.

8113{
8114 if( qty <= 0 ) {
8115 debugmsg( "Tried to reload zero or less charges" );
8116 return false;
8117 }
8118 item *ammo = loc.get_item();
8119 if( ammo == nullptr || ammo->is_null() ) {
8120 debugmsg( "Tried to reload using non-existent ammo" );
8121 return false;
8122 }
8123
8124 item *container = nullptr;
8125 if( ammo->is_ammo_container() || ammo->is_container() ) {
8126 container = ammo;
8127 ammo = &ammo->contents.front();
8128 }
8129
8130 if( !is_reloadable_with( ammo->typeId() ) ) {
8131 return false;
8132 }
8133
8134 // limit quantity of ammo loaded to remaining capacity
8135 int limit = is_watertight_container()
8138
8139 if( ammo->ammo_type() == ammo_plutonium ) {
8140 limit = limit / PLUTONIUM_CHARGES + ( limit % PLUTONIUM_CHARGES != 0 );
8141 }
8142
8143 qty = std::min( qty, limit );
8144
8145 casings_handle( [&u]( item & e ) {
8146 return u.i_add_or_drop( e );
8147 } );
8148
8149 if( is_magazine() ) {
8150 qty = std::min( qty, ammo->charges );
8151
8152 if( is_ammo_belt() && type->magazine->linkage ) {
8153 if( !u.use_charges_if_avail( *type->magazine->linkage, qty ) ) {
8154 debugmsg( "insufficient linkages available when reloading ammo belt" );
8155 }
8156 }
8157
8158 item to_reload = *ammo;
8159 to_reload.charges = qty;
8160 ammo->charges -= qty;
8161 bool merged = false;
8162 for( item *it : contents.all_items_top() ) {
8163 if( it->merge_charges( to_reload ) ) {
8164 merged = true;
8165 break;
8166 }
8167 }
8168 if( !merged ) {
8169 put_in( to_reload );
8170 }
8171 } else if( is_watertight_container() ) {
8172 if( !ammo->made_of( LIQUID ) ) {
8173 debugmsg( "Tried to reload liquid container with non-liquid." );
8174 return false;
8175 }
8176 if( container ) {
8177 container->on_contents_changed();
8178 }
8179 fill_with( *ammo, qty );
8180 } else if( !magazine_integral() ) {
8181 // if we already have a magazine loaded prompt to eject it
8182 if( magazine_current() ) {
8183 //~ %1$s: magazine name, %2$s: weapon name
8184 std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ),
8185 magazine_current()->tname(), tname() );
8186
8187 // eject magazine to player inventory and try to dispose of it from there
8188 item &mag = u.i_add( *magazine_current() );
8189 if( !u.dispose_item( item_location( u, &mag ), prompt ) ) {
8190 u.remove_item( mag ); // user canceled so delete the clone
8191 return false;
8192 }
8194 }
8195
8196 put_in( *ammo );
8197 loc.remove_item();
8198 return true;
8199
8200 } else {
8201 if( ammo->has_flag( flag_SPEEDLOADER ) ) {
8202 curammo = ammo->contents.front().type;
8203 qty = std::min( qty, ammo->ammo_remaining() );
8204 ammo->ammo_consume( qty, tripoint_zero );
8205 charges += qty;
8206 } else if( ammo->ammo_type() == ammo_plutonium ) {
8207 curammo = ammo->type;
8208 ammo->charges -= qty;
8209
8210 // any excess is wasted rather than overfilling the item
8211 charges += qty * PLUTONIUM_CHARGES;
8212 charges = std::min( charges, ammo_capacity() );
8213 } else {
8214 curammo = ammo->type;
8215 qty = std::min( qty, ammo->charges );
8216 ammo->charges -= qty;
8217 charges += qty;
8218 }
8219 }
8220
8221 if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
8222 if( container != nullptr ) {
8223 container->remove_item( container->contents.front() );
8224 u.inv.restack( u ); // emptied containers do not stack with non-empty ones
8225 } else {
8226 loc.remove_item();
8227 }
8228 }
8229 return true;
8230}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2268
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2408
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7270
void restack(player &p)
Definition: inventory.cpp:400
item * get_item()
Gets the selected item or nullptr.
void remove_item()
Removes the selected item from the game.
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8569
bool is_ammo_belt() const
Definition: item.cpp:6577
static constexpr int PLUTONIUM_CHARGES
static const ammotype ammo_plutonium("plutonium")
static const std::string flag_SPEEDLOADER("SPEEDLOADER")
@ prompt
Definition: pickup.h:30
static constexpr tripoint tripoint_zero
Definition: point.h:259

References item_contents::all_items_top(), ammo_capacity(), ammo_consume(), ammo_plutonium, ammo_remaining(), ammo_type(), casings_handle(), charges, contents, curammo, debugmsg, Character::dispose_item(), fill_with(), flag_SPEEDLOADER(), item_contents::front(), item_location::get_item(), get_remaining_capacity_for_liquid(), has_flag(), Character::i_add(), Character::i_add_or_drop(), Character::inv, is_ammo_belt(), is_ammo_container(), is_container(), is_magazine(), is_null(), is_reloadable_with(), is_watertight_container(), LIQUID, made_of(), itype::magazine, magazine_current(), magazine_integral(), on_contents_changed(), pgettext(), PLUTONIUM_CHARGES, pickup::prompt, put_in(), item_location::remove_item(), visitable< item >::remove_item(), visitable< T >::remove_item(), inventory::restack(), string_format(), tname(), tripoint_zero, type, typeId(), and Character::use_charges_if_avail().

Referenced by veh_interact::complete_vehicle(), npc::do_reload(), ranged::fire_gun(), and activity_handlers::reload_finish().

◆ remove_old_owner()

void item::remove_old_owner ( ) const
inline

Definition at line 2032 of file item.h.

2032 {
2034 }

References string_id< faction >::NULL_ID().

Referenced by talk_function::drop_stolen_item(), and validate_ownership().

◆ remove_owner()

void item::remove_owner ( ) const
inline

Definition at line 2039 of file item.h.

2039 {
2041 }

References string_id< faction >::NULL_ID().

Referenced by validate_ownership().

◆ repair_info()

void item::repair_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3175 of file item.cpp.

3177{
3179 return;
3180 }
3182 const std::vector<itype_id> &rep = sorted_lex( repaired_with() );
3183 if( !rep.empty() ) {
3184 info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Repair</bold> using %s." ),
3185 enumerate_as_string( rep.begin(), rep.end(), []( const itype_id & e ) {
3186 return nname( e );
3188 if( reinforceable() ) {
3189 info.emplace_back( "DESCRIPTION", _( "* This item can be <good>reinforced</good>." ) );
3190 }
3191 } else {
3192 info.emplace_back( "DESCRIPTION", _( "* This item is <bad>not repairable</bad>." ) );
3193 }
3194}
bool reinforceable() const
Whether the item can be repaired beyond normal health.
Definition: item.cpp:6509
const std::set< itype_id > & repaired_with() const
If possible to repair this item what tools could potentially be used for this purpose?
Definition: item.cpp:6367

References _, DESCRIPTION_REPAIREDWITH, enumerate_as_string(), info(), insert_separation_line(), or_, reinforceable(), repaired_with(), sorted_lex(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ repaired_with()

const std::set< itype_id > & item::repaired_with ( ) const

If possible to repair this item what tools could potentially be used for this purpose?

Definition at line 6367 of file item.cpp.

6368{
6369 static std::set<itype_id> no_repair;
6370 return has_flag( flag_NO_REPAIR ) ? no_repair : type->repair;
6371}
std::set< itype_id > repair
Damage scale compared to the old float damage value.
Definition: itype.h:982

References flag_NO_REPAIR(), has_flag(), itype::repair, and type.

Referenced by repair_info().

◆ reset_cable()

void item::reset_cable ( player p)

Helper to bring a cable back to its initial state.

Definition at line 9425 of file item.cpp.

9426{
9427 int max_charges = type->maximum_charges();
9428
9429 set_var( "state", "attach_first" );
9430 erase_var( "source_x" );
9431 erase_var( "source_y" );
9432 erase_var( "source_z" );
9433 active = false;
9434 charges = max_charges;
9435
9436 if( p != nullptr ) {
9437 p->add_msg_if_player( m_info, _( "You reel in the cable." ) );
9438 p->moves -= charges * 10;
9439 }
9440}

References _, active, player::add_msg_if_player(), charges, erase_var(), m_info, itype::maximum_charges(), Creature::moves, set_var(), and type.

Referenced by process_cable().

◆ rotten()

◆ serialize()

void item::serialize ( JsonOut json) const

Definition at line 2392 of file savegame_json.cpp.

2393{
2394 io::JsonObjectOutputArchive archive( json );
2395 const_cast<item *>( this )->io( archive );
2396 if( !contents.empty() ) {
2397 json.member( "contents", contents );
2398 }
2399}
void member(const std::string &name)
Definition: json.cpp:2235
Output archive matching the input archive JsonObjectInputArchive.
Definition: cata_io.h:351

References contents, item_contents::empty(), io(), and JsonOut::member().

Referenced by contain_monster().

◆ set_age()

void item::set_age ( const time_duration age)

Definition at line 10017 of file item.cpp.

10018{
10020}
void set_birthday(const time_point &bday)
Definition: item.cpp:10038

References age(), set_birthday(), and calendar::turn.

Referenced by burn(), iuse::firecracker_pack(), iuse::fish_trap(), vehicle::operate_planter(), and map::process_fields_in_submap().

◆ set_birthday()

void item::set_birthday ( const time_point bday)

Definition at line 10038 of file item.cpp.

10039{
10040 this->bday = std::max( calendar::turn_zero, bday );
10041}

References bday, and calendar::turn_zero.

Referenced by editmap::edit_itm(), retroactively_fill_from_funnel(), set_age(), and debug_menu::wishitem().

◆ set_cached_tool_selections()

void item::set_cached_tool_selections ( const std::vector< comp_selection< tool_comp > > &  selections)

Definition at line 10119 of file item.cpp.

10120{
10121 assert( craft_data_ );
10122 craft_data_->cached_tool_selections = selections;
10123}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_countdown()

void item::set_countdown ( int  num_turns)

Sets time until activation for an item that will self-activate in the future.

Definition at line 8604 of file item.cpp.

8605{
8606 if( num_turns < 0 ) {
8607 debugmsg( "Tried to set a negative countdown value %d.", num_turns );
8608 return;
8609 }
8610 if( !ammo_types().empty() ) {
8611 debugmsg( "Tried to set countdown on an item with ammo." );
8612 return;
8613 }
8614 charges = num_turns;
8615}

References ammo_types(), charges, and debugmsg.

Referenced by iuse_transform::use().

◆ set_damage()

item & item::set_damage ( int  qty)

Filter setting damage constrained by min_damage and max_damage.

Note
this method does not invoke the on_damage callback
Returns
same instance to allow method chaining

Definition at line 719 of file item.cpp.

720{
721 on_damage( qty - damage_, DT_TRUE );
722 damage_ = std::max( std::min( qty, max_damage() ), min_damage() );
723 return *this;
724}

References damage_, DT_TRUE, max_damage(), min_damage(), and on_damage().

Referenced by mdeath::broken(), editmap::edit_itm(), iuse::gun_repair(), Item_modifier::modify(), vehicle_part::properties_to_item(), repair_item_actor::repair(), game::save_cyborg(), vehicle::set_hp(), and map::spawn_an_item().

◆ set_favorite()

void item::set_favorite ( bool  favorite)

Definition at line 10091 of file item.cpp.

10092{
10093 is_favorite = favorite;
10094}

References is_favorite.

Referenced by advanced_inventory::display(), and inventory_column::set_stack_favorite().

◆ set_flag()

item & item::set_flag ( const std::string &  flag)

Idempotent filter setting an item specific flag.

Definition at line 5359 of file item.cpp.

5360{
5361 item_tags.insert( flag );
5362 return *this;
5363}
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151

References cata::flat_set< T, Compare, Data >::insert(), and item_tags.

Referenced by map::add_corpse(), ammo_set(), are_requirements_nearby(), iexamine::autodoc(), explosion_handler::ExplosionProcess::blast_tile(), butcher_cbm_item(), activity_handlers::butcher_finish(), butchery_quarter(), iuse::camera(), complete_craft(), crafting::complete_disassemble(), recipe::create_byproducts(), Single_item_creator::create_single(), cycle_action(), game::dump_stats(), Character::eat(), heal_actor::finish_using(), basecamp::form_crafting_inventory(), inventory::form_from_map(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iuse_transform::info(), inherit_flags(), init_memory_card_with_random_stuff(), item(), Item_factory::migrate_item(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), iexamine::nanofab(), on_damage(), on_drop(), process_rot(), vehicle_part::properties_to_item(), iuse::radio_mod(), activity_handlers::reload_finish(), repair_item_actor::repair(), mattack::riotbot(), set_flag_recursive(), spell_effect::spawn_ethereal_item(), map::spawn_item(), starting_clothes(), starting_inv(), iuse::towel_common(), avatar_funcs::unload_item(), sew_advanced_actor::use(), unpack_actor::use(), iexamine::use_furn_fake_item(), and vehicle_part::vehicle_part().

◆ set_flag_recursive()

item & item::set_flag_recursive ( const std::string &  flag)

Idempotent filter recursively setting an item specific flag on this item and its components.

Definition at line 5371 of file item.cpp.

5372{
5373 set_flag( flag );
5374 for( item &comp : components ) {
5375 comp.set_flag_recursive( flag );
5376 }
5377 return *this;
5378}

References components, and set_flag().

◆ set_mtype()

void item::set_mtype ( const mtype m)

Sets the monster type associated with this item (corpse).

You must not pass a null pointer. TODO: change this to take a reference instead.

Definition at line 6662 of file item.cpp.

6663{
6664 // This is potentially dangerous, e.g. for corpse items, which *must* have a valid mtype pointer.
6665 if( m == nullptr ) {
6666 debugmsg( "setting item::corpse of %s to NULL", tname() );
6667 return;
6668 }
6669 corpse = m;
6670}

References corpse, debugmsg, and tname().

Referenced by iuse::blood_draw().

◆ set_next_failure_point()

void item::set_next_failure_point ( const player crafter)

Calculates and sets the next failure point for an in progress craft.

Causes a debugmsg if called on non-craft.

Parameters
crafterthe crafting player

Definition at line 905 of file crafting.cpp.

906{
907 if( !is_craft() ) {
908 debugmsg( "set_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
909 return;
910 }
911
912 const int percent_left = 10000000 - item_counter;
913 const int failure_point_delta = crafter.crafting_success_roll( get_making() ) * percent_left;
914
915 craft_data_->next_failure_point = item_counter + failure_point_delta;
916}

References craft_data_, player::crafting_success_roll(), debugmsg, get_making(), is_craft(), item_counter, and tname().

Referenced by craft_command::create_in_progress_craft(), and handle_craft_failure().

◆ set_old_owner()

void item::set_old_owner ( const faction_id temp_owner)
inline

Definition at line 2029 of file item.h.

2029 {
2030 old_owner = temp_owner;
2031 }

Referenced by handle_pickup_ownership().

◆ set_owner() [1/2]

void item::set_owner ( const Character c)

Definition at line 1275 of file item.cpp.

1276{
1277 if( !c.get_faction() ) {
1278 debugmsg( "item::set_owner() Character %s has no valid faction", c.disp_name() );
1279 return;
1280 }
1281 owner = c.get_faction()->id;
1282}

References c, debugmsg, and owner.

◆ set_owner() [2/2]

◆ set_relative_rot()

void item::set_relative_rot ( double  val)

Set current item rot relative to shelf life (no-op if item does not spoil)

Definition at line 5566 of file item.cpp.

5567{
5568 if( goes_bad() ) {
5569 rot = get_shelf_life() * val;
5570 // calc_rot uses last_rot_check (when it's not turn_zero) instead of bday.
5571 // this makes sure the rotting starts from now, not from bday.
5572 // if this item is the result of smoking or milling don't do this, we want to start from bday.
5575 }
5576 }
5577}
static const std::string flag_PROCESSING_RESULT("PROCESSING_RESULT")

References flag_PROCESSING_RESULT(), get_shelf_life(), goes_bad(), has_flag(), last_rot_check, and calendar::turn.

Referenced by complete_craft(), fill_with(), item(), and iexamine::keg().

◆ set_rot()

void item::set_rot ( time_duration  val)

Definition at line 5579 of file item.cpp.

5580{
5581 rot = val;
5582}

◆ set_side()

bool item::set_side ( side  s)

Change the side on which the item is worn.

Returns false if the item is not sided

Definition at line 820 of file item.cpp.

821{
822 if( !is_sided() ) {
823 return false;
824 }
825
826 if( s == side::BOTH ) {
827 erase_var( "lateral" );
828 } else {
829 set_var( "lateral", static_cast<int>( s ) );
830 }
831
832 return true;
833}

References BOTH, erase_var(), is_sided(), and set_var().

Referenced by on_takeoff(), on_wear(), and swap_side().

◆ set_snippet()

void item::set_snippet ( const snippet_id id)

Set the snippet text (description) of this specific item, using the snippet library.

See also
snippet_library.

Definition at line 8680 of file item.cpp.

8681{
8682 if( is_null() ) {
8683 return;
8684 }
8685 if( !id.is_valid() ) {
8686 debugmsg( "there's no snippet with id %s", id.str() );
8687 return;
8688 }
8689 snip_id = id;
8690}

References debugmsg, base_camps::id, is_null(), and snip_id.

Referenced by profession::items().

◆ set_tools_to_continue()

void item::set_tools_to_continue ( bool  value)

Definition at line 10107 of file item.cpp.

10108{
10109 assert( craft_data_ );
10110 craft_data_->tools_to_continue = value;
10111}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_var() [1/6]

void item::set_var ( const std::string &  name,
const std::string &  value 
)

Definition at line 1061 of file item.cpp.

1062{
1063 item_vars[name] = value;
1064}

References item_vars, and om_direction::name().

◆ set_var() [2/6]

void item::set_var ( const std::string &  name,
const tripoint value 
)

Definition at line 1044 of file item.cpp.

1045{
1046 item_vars[name] = string_format( "%d,%d,%d", value.x, value.y, value.z );
1047}
int y
Definition: point.h:137
int x
Definition: point.h:136

References item_vars, om_direction::name(), string_format(), tripoint::x, tripoint::y, and tripoint::z.

◆ set_var() [3/6]

void item::set_var ( const std::string &  name,
double  value 
)

Definition at line 1030 of file item.cpp.

1031{
1032 item_vars[name] = string_format( "%f", value );
1033}

References item_vars, om_direction::name(), and string_format().

◆ set_var() [4/6]

◆ set_var() [5/6]

void item::set_var ( const std::string &  name,
long long  value 
)

Definition at line 1013 of file item.cpp.

1014{
1015 std::ostringstream tmpstream;
1016 tmpstream.imbue( std::locale::classic() );
1017 tmpstream << value;
1018 item_vars[name] = tmpstream.str();
1019}

References item_vars, and om_direction::name().

◆ set_var() [6/6]

void item::set_var ( const std::string &  name,
long  value 
)

Definition at line 1022 of file item.cpp.

1023{
1024 std::ostringstream tmpstream;
1025 tmpstream.imbue( std::locale::classic() );
1026 tmpstream << value;
1027 item_vars[name] = tmpstream.str();
1028}

References item_vars, and om_direction::name().

◆ sight_dispersion()

int item::sight_dispersion ( ) const

Get lowest dispersion of either integral or any attached sights.

Definition at line 7258 of file item.cpp.

7259{
7260 if( !is_gun() ) {
7261 return 0;
7262 }
7263
7264 int res = has_flag( flag_DISABLE_SIGHTS ) ? 90 : type->gun->sight_dispersion;
7265
7266 for( const item *e : gunmods() ) {
7267 const islot_gunmod &mod = *e->type->gunmod;
7268 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
7269 continue; // skip gunmods which don't provide a sight
7270 }
7271 res = std::min( res, mod.sight_dispersion );
7272 }
7273
7274 return res;
7275}

References flag_DISABLE_SIGHTS(), itype::gun, gunmods(), has_flag(), is_gun(), and type.

Referenced by ranged::get_aim_types(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ simulate_burn()

float item::simulate_burn ( fire_data frd) const

Calculate all burning calculations, but don't actually apply them to item.

DO apply them to fire_data argument, though.

Returns
Amount of "burn" that would be applied to the item.

Definition at line 8232 of file item.cpp.

8233{
8234 const std::vector<material_id> &mats = made_of();
8235 float smoke_added = 0.0f;
8236 float time_added = 0.0f;
8237 float burn_added = 0.0f;
8238 const units::volume vol = base_volume();
8239 const int effective_intensity = frd.contained ? 3 : frd.fire_intensity;
8240 for( const material_id &m : mats ) {
8241 const mat_burn_data &bd = m.obj().burn_data( effective_intensity );
8242 if( bd.immune ) {
8243 // Made to protect from fire
8244 return 0.0f;
8245 }
8246
8247 // If fire is contained, burn rate is independent of volume
8248 if( frd.contained || bd.volume_per_turn == 0_ml ) {
8249 time_added += bd.fuel;
8250 smoke_added += bd.smoke;
8251 burn_added += bd.burn;
8252 } else {
8253 double volume_burn_rate = to_liter( bd.volume_per_turn ) / to_liter( vol );
8254 time_added += bd.fuel * volume_burn_rate;
8255 smoke_added += bd.smoke * volume_burn_rate;
8256 burn_added += bd.burn * volume_burn_rate;
8257 }
8258 }
8259
8260 // Liquids that don't burn well smother fire well instead
8261 if( made_of( LIQUID ) && time_added < 200 ) {
8262 time_added -= rng( 400.0 * to_liter( vol ), 1200.0 * to_liter( vol ) );
8263 } else if( mats.size() > 1 ) {
8264 // Average the materials
8265 time_added /= mats.size();
8266 smoke_added /= mats.size();
8267 burn_added /= mats.size();
8268 } else if( mats.empty() ) {
8269 // Non-liquid items with no specified materials will burn at moderate speed
8270 burn_added = 1;
8271 }
8272
8273 if( count_by_charges() ) {
8274 int stack_burnt = rng( type->stack_size / 2, type->stack_size );
8275 time_added *= stack_burnt;
8276 smoke_added *= stack_burnt;
8277 burn_added *= stack_burnt;
8278 }
8279
8280 frd.fuel_produced += time_added;
8281 frd.smoke_produced += smoke_added;
8282 return burn_added;
8283}
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
int fire_intensity
Current intensity of the fire.
Definition: fire.h:25
float fuel_produced
Fuel contributed by each burning item this turn is summed here.
Definition: fire.h:29
float smoke_produced
Smoke produced by each burning item this turn is summed here.
Definition: fire.h:27
bool contained
The fire is contained and burned for fuel intentionally.
Definition: fire.h:31
float smoke
Smoke produced per tick when this material burns.
Definition: fire.h:54
float burn
Volume of material destroyed per tick when this material burns.
Definition: fire.h:56

References base_volume(), mat_burn_data::burn, fire_data::contained, count_by_charges(), fire_data::fire_intensity, mat_burn_data::fuel, fire_data::fuel_produced, mat_burn_data::immune, LIQUID, made_of(), rng(), mat_burn_data::smoke, fire_data::smoke_produced, itype::stack_size, units::to_liter(), type, and mat_burn_data::volume_per_turn.

Referenced by burn(), and try_fuel_fire().

◆ spill_contents() [1/2]

bool item::spill_contents ( Character c)

Unloads the item's contents.

Parameters
cCharacter who receives the contents. If c is the player, liquids will be handled, otherwise they will be spilled.
Returns
If the item is now empty.

Definition at line 7069 of file item.cpp.

7070{
7071 if( !is_container() || is_container_empty() ) {
7072 return true;
7073 }
7074
7075 if( c.is_npc() ) {
7076 return spill_contents( c.pos() );
7077 }
7078
7081
7082 return true;
7083}
void handle_liquid_or_spill(Character &guy)
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:7069

References c, contents, item_contents::handle_liquid_or_spill(), is_container(), is_container_empty(), on_contents_changed(), and spill_contents().

Referenced by drop_or_embed_projectile(), pickup::handle_spillable_contents(), Character::i_rem_keep_contents(), pick_one_up(), smash(), and spill_contents().

◆ spill_contents() [2/2]

bool item::spill_contents ( const tripoint pos)

Unloads the item's contents.

Parameters
posPosition to dump the contents on.
Returns
If the item is now empty.

Definition at line 7085 of file item.cpp.

7086{
7087 if( !is_container() || is_container_empty() ) {
7088 return true;
7089 }
7090
7091 for( item *it : contents.all_items_top() ) {
7092 get_map().add_item_or_charges( pos, *it );
7093 }
7094
7096 return true;
7097}
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4355

References map::add_item_or_charges(), item_contents::all_items_top(), item_contents::clear_items(), contents, get_map(), is_container(), and is_container_empty().

◆ split()

item item::split ( int  qty)

Splits a count-by-charges item always leaving source item with minimum of 1 charge.

Parameters
qtynumber of required charges to split from source
Returns
new instance containing exactly qty charges or null item if splitting failed

Definition at line 726 of file item.cpp.

727{
728 if( !count_by_charges() || qty <= 0 || qty >= charges ) {
729 return item();
730 }
731 item res = *this;
732 res.charges = qty;
733 charges -= qty;
734 return res;
735}

References charges, count_by_charges(), and item().

Referenced by iexamine::gaspump(), Character::item_reload_cost(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), and bandolier_actor::reload().

◆ spoilage_sort_order()

int item::spoilage_sort_order ( ) const

Get time left to rot, ignoring fridge.

Returns time to rot if item is able to, max int - N otherwise, where N is 3 for food, 2 for medication, 1 for other comestibles, 0 otherwise.

Definition at line 5584 of file item.cpp.

5585{
5586 const item *subject;
5587 constexpr int bottom = std::numeric_limits<int>::max();
5588
5589 if( type->container && !contents.empty() ) {
5590 if( type->container->preserves ) {
5591 return bottom - 3;
5592 }
5593 subject = &contents.front();
5594 } else {
5595 subject = this;
5596 }
5597
5598 if( subject->goes_bad() ) {
5599 return to_turns<int>( subject->get_shelf_life() - subject->rot );
5600 }
5601
5602 if( subject->get_comestible() ) {
5603 if( subject->get_category().get_id() == itemcat_food ) {
5604 return bottom - 3;
5605 } else if( subject->get_category().get_id() == itemcat_drugs ) {
5606 return bottom - 2;
5607 } else {
5608 return bottom - 1;
5609 }
5610 }
5611 return bottom;
5612}
static const item_category_id itemcat_drugs("drugs")
static const item_category_id itemcat_food("food")

References itype::container, contents, item_contents::empty(), item_contents::front(), get_category(), get_comestible(), item_category::get_id(), get_shelf_life(), goes_bad(), itemcat_drugs, itemcat_food, rot, and type.

Referenced by find_auto_consume().

◆ stab_resist()

int item::stab_resist ( bool  to_self = false) const

Definition at line 6102 of file item.cpp.

6103{
6104 // Better than hardcoding it in multiple places
6105 return static_cast<int>( 0.8f * cut_resist( to_self ) );
6106}

References cut_resist().

Referenced by damage_resist().

◆ stacks_with()

bool item::stacks_with ( const item rhs,
bool  check_components = false,
bool  skip_type_check = false 
) const

Definition at line 894 of file item.cpp.

895{
896 if( !skip_type_check && type != rhs.type ) {
897 return false;
898 }
899 if( is_relic() && rhs.is_relic() && !( *relic_data == *rhs.relic_data ) ) {
900 return false;
901 }
902 if( charges != 0 && rhs.charges != 0 && is_money() ) {
903 // Dealing with nonempty cash cards
904 return true;
905 }
906 // This function is also used to test whether items counted by charges should be merged, for that
907 // check the, the charges must be ignored. In all other cases (tools/guns), the charges are important.
908 if( !count_by_charges() && charges != rhs.charges ) {
909 return false;
910 }
911 if( is_favorite != rhs.is_favorite ) {
912 return false;
913 }
914 if( damage_ != rhs.damage_ ) {
915 return false;
916 }
917 if( burnt != rhs.burnt ) {
918 return false;
919 }
920 if( active != rhs.active ) {
921 return false;
922 }
923 if( item_tags != rhs.item_tags ) {
924 return false;
925 }
926 if( faults != rhs.faults ) {
927 return false;
928 }
929 if( techniques != rhs.techniques ) {
930 return false;
931 }
932 if( item_vars != rhs.item_vars ) {
933 return false;
934 }
935 if( goes_bad() && rhs.goes_bad() ) {
936 // Stack items that fall into the same "bucket" of freshness.
937 // Distant buckets are larger than near ones.
938 std::pair<int, clipped_unit> my_clipped_time_to_rot =
940 std::pair<int, clipped_unit> other_clipped_time_to_rot =
941 clipped_time( rhs.get_shelf_life() - rhs.rot );
942 if( my_clipped_time_to_rot != other_clipped_time_to_rot ) {
943 return false;
944 }
945 if( rotten() != rhs.rotten() ) {
946 // just to be safe that rotten and unrotten food is *never* stacked.
947 return false;
948 }
949 }
950 if( ( corpse == nullptr && rhs.corpse != nullptr ) ||
951 ( corpse != nullptr && rhs.corpse == nullptr ) ) {
952 return false;
953 }
954 if( corpse != nullptr && rhs.corpse != nullptr && corpse->id != rhs.corpse->id ) {
955 return false;
956 }
957 if( craft_data_ || rhs.craft_data_ ) {
958 // In-progress crafts are always distinct items. Easier to handle for the player,
959 // and there shouldn't be that many items of this type around anyway.
960 return false;
961 }
962 if( check_components || is_comestible() || is_craft() ) {
963 //Only check if at least one item isn't using the default recipe or is comestible
964 if( !components.empty() || !rhs.components.empty() ) {
966 return false;
967 }
968 }
969 }
971 return false;
972 }
973
974 if( ammo_current() != rhs.ammo_current() ) {
975 return false;
976 }
977
978 return contents.stacks_with( rhs.contents );
979}
std::pair< int, clipped_unit > clipped_time(const time_duration &d)
Returns a value representing the passed in duration truncated to an appropriate unit along with the u...
Definition: calendar.cpp:284
bool stacks_with(const item_contents &rhs) const
std::vector< item_comp > get_uncraft_components() const
Returns a list of components used to craft this item or the default components if it wasn't player-cr...
Definition: item.cpp:10064

References active, ammo_current(), burnt, charges, clipped_time(), components, contents, corpse, count_by_charges(), craft_data_, damage_, faults, get_shelf_life(), get_uncraft_components(), goes_bad(), mtype::id, is_comestible(), is_craft(), is_favorite, is_money(), is_relic(), item_tags, item_vars, item_contents::num_item_stacks(), relic_data, rot, rotten(), item_contents::stacks_with(), techniques, and type.

Referenced by display_stacked_with(), merge_charges(), inventory::restack(), inventory_column::set_stack_favorite(), and npc_trading::transfer_items().

◆ swap_side()

bool item::swap_side ( )

Swap the side on which the item is worn.

Returns false if the item is not sided

Definition at line 835 of file item.cpp.

836{
837 return set_side( opposite_side( get_side() ) );
838}
side opposite_side(side s)
Returns the opposite side.
Definition: bodypart.cpp:30

References get_side(), opposite_side(), and set_side().

Referenced by Character::change_side().

◆ symbol()

const std::string & item::symbol ( ) const

Definition at line 4144 of file item.cpp.

4145{
4146 return type->sym;
4147}
std::string sym
Definition: itype.h:976

References itype::sym, and type.

Referenced by map::draw_maptile(), map_memory::load_legacy(), mm_elem::operator==(), pickup::pick_up(), mm_submap::serialize(), and debug_menu::wishitem().

◆ tname()

std::string item::tname ( unsigned int  quantity = 1,
bool  with_prefix = true,
unsigned int  truncate = 0 
) const

Return the (translated) item name.

Parameters
quantityused for translation to the proper plural form of the name, e.g. returns "rock" for quantity 1 and "rocks" for quantity > 0.
with_prefixdetermines whether to include more item properties, such as the extent of damage and burning (was created to sort by name without prefix in additional inventory)

Definition at line 4576 of file item.cpp.

4577{
4578 int dirt_level = get_var( "dirt", 0 ) / 2000;
4579 std::string dirt_symbol;
4580 // TODO: MATERIALS put this in json
4581
4582 // these symbols are unicode square characeters of different heights, representing a rough
4583 // estimation of fouling in a gun. This appears instead of "faulty"
4584 // since most guns will have some level of fouling in them, and usually it is not a big deal.
4585 switch( dirt_level ) {
4586 case 0:
4587 dirt_symbol = "";
4588 break;
4589 case 1:
4590 dirt_symbol = "<color_white>\u2581</color>";
4591 break;
4592 case 2:
4593 dirt_symbol = "<color_light_gray>\u2583</color>";
4594 break;
4595 case 3:
4596 dirt_symbol = "<color_light_gray>\u2585</color>";
4597 break;
4598 case 4:
4599 dirt_symbol = "<color_dark_gray>\u2587</color>";
4600 break;
4601 case 5:
4602 dirt_symbol = "<color_brown>\u2588</color>";
4603 break;
4604 default:
4605 dirt_symbol = "";
4606 }
4607 std::string damtext;
4608
4609 // for portions of string that have <color_ etc in them, this aims to truncate the whole string correctly
4610 unsigned int truncate_override = 0;
4611
4612 if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
4613 with_prefix ) {
4614 damtext = durability_indicator();
4615 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
4616 // get the utf8 width of the tags
4617 truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
4618 }
4619 }
4620 if( !faults.empty() ) {
4621 bool silent = true;
4622 for( const auto &fault : faults ) {
4623 if( !fault->has_flag( flag_SILENT ) ) {
4624 silent = false;
4625 break;
4626 }
4627 }
4628 if( silent ) {
4629 damtext.insert( 0, dirt_symbol );
4630 } else {
4631 damtext.insert( 0, _( "faulty " ) + dirt_symbol );
4632 }
4633 }
4634
4635 std::string vehtext;
4636 if( is_engine() && engine_displacement() > 0 ) {
4637 vehtext = string_format( pgettext( "vehicle adjective", "%2.1fL " ),
4638 engine_displacement() / 100.0f );
4639
4640 } else if( is_wheel() && type->wheel->diameter > 0 ) {
4641 vehtext = string_format( pgettext( "vehicle adjective", "%d\" " ), type->wheel->diameter );
4642 }
4643
4644 std::string burntext;
4645 if( with_prefix && !made_of( LIQUID ) ) {
4646 if( volume() >= 1_liter && burnt * 125_ml >= volume() ) {
4647 burntext = pgettext( "burnt adjective", "badly burnt " );
4648 } else if( burnt > 0 ) {
4649 burntext = pgettext( "burnt adjective", "burnt " );
4650 }
4651 }
4652
4653 std::string maintext;
4654 if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
4655 maintext = type_name( quantity );
4656 } else if( is_gun() || is_tool() || is_magazine() ) {
4657 int amt = 0;
4658 maintext = label( quantity );
4659 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
4660 if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
4661 amt++;
4662 }
4663 }
4664 if( amt ) {
4665 maintext += string_format( "+%d", amt );
4666 }
4667 } else if( is_armor() && has_clothing_mod() ) {
4668 maintext = label( quantity ) + "+1";
4669 } else if( is_craft() ) {
4670 maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
4671 if( charges > 1 ) {
4672 maintext += string_format( " (%d)", charges );
4673 }
4674 const int percent_progress = item_counter / 100000;
4675 maintext += string_format( " (%d%%)", percent_progress );
4676 } else if( contents.num_item_stacks() == 1 ) {
4677 const item &contents_item = contents.front();
4678 const unsigned contents_count =
4679 ( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
4680 contents_item.charges > 1 )
4681 ? contents_item.charges
4682 : quantity;
4683 maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
4684 contents_item.tname( contents_count, with_prefix ) );
4685 } else if( !contents.empty() ) {
4686 maintext = string_format( vpgettext( "item name",
4687 //~ %1$s: item name, %2$zd: content size
4688 "%1$s with %2$zd item",
4689 "%1$s with %2$zd items", contents.num_item_stacks() ),
4690 label( quantity ), contents.num_item_stacks() );
4691 } else {
4692 maintext = label( quantity );
4693 }
4694
4695 avatar &you = get_avatar();
4696 std::string tagtext;
4697 if( is_food() ) {
4699 tagtext += _( " (poisonous)" );
4700 } else if( has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 ) {
4701 tagtext += _( " (hallucinogenic)" );
4702 }
4703 }
4704 if( is_book() ) {
4705 if( !you.has_identified( typeId() ) ) {
4706 tagtext += _( " (unread)" );
4707 }
4708 }
4709 if( has_var( "bionics_scanned_by" ) && has_flag( flag_CBM_SCANNED ) ) {
4710 tagtext += _( " (bionic detected)" );
4711 }
4712 if( has_flag( flag_ETHEREAL_ITEM ) ) {
4713 tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
4714 } else if( goes_bad() || is_food() ) {
4715 if( has_own_flag( "DIRTY" ) ) {
4716 tagtext += _( " (dirty)" );
4717 } else if( rotten() ) {
4718 tagtext += _( " (rotten)" );
4719 } else if( is_going_bad() ) {
4720 tagtext += _( " (old)" );
4721 } else if( is_fresh() ) {
4722 tagtext += _( " (fresh)" );
4723 }
4724 if( has_flag( flag_COLD ) ) {
4725 tagtext += _( " (cold)" );
4726 } else if( has_flag( flag_VERY_COLD ) ) {
4727 tagtext += _( " (very cold)" );
4728 }
4729 }
4730
4731 const sizing sizing_level = get_sizing( you, get_encumber( you ) != 0 );
4732
4733 if( sizing_level == sizing::human_sized_small_char ) {
4734 tagtext += _( " (too big)" );
4735 } else if( sizing_level == sizing::big_sized_small_char ) {
4736 tagtext += _( " (huge!)" );
4737 } else if( sizing_level == sizing::human_sized_big_char ||
4738 sizing_level == sizing::small_sized_human_char ) {
4739 tagtext += _( " (too small)" );
4740 } else if( sizing_level == sizing::small_sized_big_char ) {
4741 tagtext += _( " (tiny!)" );
4742 } else if( !has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
4743 tagtext += _( " (poor fit)" );
4744 }
4745
4746 if( is_filthy() ) {
4747 tagtext += _( " (filthy)" );
4748 }
4750 tagtext += _( " (sterile)" );
4751 }
4752
4753 if( is_tool() && has_flag( flag_USE_UPS ) && !has_flag( flag_NAT_UPS ) ) {
4754 tagtext += _( " (UPS)" );
4755 }
4756 if( is_tool() && has_flag( flag_HEATS_FOOD ) ) {
4757 tagtext += _( " (heats)" );
4758 }
4759
4760 if( has_var( "NANOFAB_ITEM_ID" ) ) {
4761 tagtext += string_format( " (%s)", nname( itype_id( get_var( "NANOFAB_ITEM_ID" ) ) ) );
4762 }
4763
4764 if( has_flag( flag_RADIO_MOD ) ) {
4765 tagtext += _( " (radio:" );
4766 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
4767 tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" );
4768 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
4769 tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" );
4770 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
4771 tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" );
4772 } else {
4773 debugmsg( "Why is the radio neither red, blue, nor green?" );
4774 tagtext += "?)";
4775 }
4776 }
4777
4778 if( has_flag( flag_WET ) ) {
4779 tagtext += _( " (wet)" );
4780 }
4781 if( already_used_by_player( you ) ) {
4782 tagtext += _( " (used)" );
4783 }
4785 tagtext += _( " (lit)" );
4786 } else if( has_flag( flag_IS_UPS ) && get_var( "cable" ) == "plugged_in" ) {
4787 tagtext += _( " (plugged in)" );
4788 } else if( active && !is_food() && !is_corpse() &&
4789 !string_ends_with( typeId().str(), "_on" ) ) {
4790 // Usually the items whose ids end in "_on" have the "active" or "on" string already contained
4791 // in their name, also food is active while it rots.
4792 tagtext += _( " (active)" );
4793 }
4794
4795 if( is_favorite ) {
4796 tagtext += _( " *" ); // Display asterisk for favorite items
4797 }
4798
4799 std::string modtext;
4801 modtext += _( "sawn-off " );
4802 }
4804 modtext += _( "pistol " );
4805 }
4806 if( has_flag( flag_DIAMOND ) ) {
4807 modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " ";
4808 }
4809
4810 //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)").
4811 std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext,
4812 vehtext, maintext, tagtext );
4813
4814 if( truncate != 0 ) {
4815 ret = utf8_truncate( ret, truncate + truncate_override );
4816 }
4817
4818 if( item_vars.find( "item_note" ) != item_vars.end() ) {
4819 //~ %s is an item name. This style is used to denote items with notes.
4820 return string_format( _( "*%s*" ), ret );
4821 } else {
4822 return ret;
4823 }
4824}
int utf8_width(const char *s, const bool ignore_tags)
std::string utf8_truncate(const std::string &s, size_t length)
bool has_flag(const std::string &flag) const
Definition: fault.h:61
bool is_wheel() const
Definition: item.cpp:6765
bool is_going_bad() const
an item is about to become rotten when shelf life has nearly elapsed
Definition: item.h:844
std::string durability_indicator(bool include_intact=false) const
Provides a prefix for the durability state of the item.
Definition: item.cpp:6326
std::string label(unsigned int quantity=0) const
Returns label from "item_label" itemvar and quantity.
Definition: item.cpp:9959
bool is_fresh() const
an item is fresh if it is capable of rotting but still has a long shelf life remaining
Definition: item.h:839
bool has_clothing_mod() const
Definition: item.cpp:10140
int engine_displacement() const
for combustion engines the displacement (cc)
Definition: item.cpp:4139
bool already_used_by_player(const player &p) const
Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific p...
Definition: item.cpp:8854
static const itype_id itype_blood("blood")
static const std::string flag_SILENT("SILENT")
static const std::string flag_HEATS_FOOD("HEATS_FOOD")
static const itype_id itype_stock_small("stock_small")
static const std::string flag_NAT_UPS("NAT_UPS")
static const itype_id itype_barrel_small("barrel_small")
static const std::string flag_CBM_SCANNED("CBM_SCANNED")
bool string_ends_with(const std::string &s1, const std::string &s2)
Returns true if s1 ends with s2.
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:286
const char * vpgettext(const char *const context, const char *const msgid, const char *const msgid_plural, const size_t n)
@ silent
Definition: weather_type.h:56

References _, active, already_used_by_player(), big_sized_small_char, burnt, charges, contents, craft_data_, damage(), debugmsg, durability_indicator(), item_contents::empty(), engine_displacement(), fault_bionic_nonsterile, faults, flag_CBM_SCANNED(), flag_COLD(), flag_DIAMOND(), flag_ETHEREAL_ITEM(), flag_FIT(), flag_HEATS_FOOD(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_IS_UPS(), flag_LITCIG(), flag_NAT_UPS(), flag_RADIO_MOD(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_SILENT(), flag_USE_UPS(), flag_VARSIZE(), flag_VERY_COLD(), flag_WATER_EXTINGUISH(), flag_WET(), item_contents::front(), get_avatar(), get_encumber(), get_sizing(), Character::get_skill_level(), get_var(), goes_bad(), itype::gun, gunmod_find(), gunmods(), has_clothing_mod(), has_fault(), fault::has_flag(), has_flag(), avatar::has_identified(), has_own_flag(), has_var(), human_sized_big_char, human_sized_small_char, is_armor(), is_bionic(), is_book(), is_corpse(), is_craft(), is_engine(), is_favorite, is_filthy(), is_food(), is_fresh(), is_going_bad(), is_gun(), is_magazine(), is_null(), is_tool(), is_wheel(), item_counter, item_vars, itype_barrel_small, itype_blood, itype_id, itype_stock_small, label(), LIQUID, made_of(), nname(), item_contents::num_item_stacks(), pgettext(), cata::hash64_detail::ret, rotten(), silent, skill_survival, small_sized_big_char, small_sized_human_char, string_ends_with(), string_format(), tname(), toolmods(), type, type_name(), typeId(), utf8_truncate(), utf8_width(), volume(), vpgettext(), and itype::wheel.

Referenced by Character::absorb_hit(), advanced_inventory::action_examine(), monexamine::add_armor(), game::add_artifact_dreams(), add_disassemblables(), MapgenRemovePartHandler::add_item_or_charges(), advanced_inventory_pane::add_items_from_area(), auto_pickup::player_settings::add_rule(), add_salvagables(), npc::alt_attack(), ammo_consume(), apply_lock_picking_tool(), apply_prying_tool(), Character::armor_absorb(), iuse::artifact(), inventory::assign_empty_invlet(), mattack::bio_op_disarm(), talk_function::bionic_remove(), Character::block_hit(), Character::block_ranged_hit(), iuse::blood_draw(), iuse::burrow(), activity_handlers::butcher_finish(), camp_car_description(), use_function::can_call(), npc::can_read(), repair_item_actor::can_repair_target(), Character::can_unwield(), Character::can_use(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), Character::change_side(), charges_per_volume(), iuse::chew(), iuse::coin_flip(), colorized_item_name(), game_menus::inv::compare(), crafting::complete_disassemble(), npc::confident_gun_mode_range(), Character::consume(), Character::consume_item(), iuse::contacts(), game_menus::inv::container_for(), iuse::craft(), auto_pickup::rule_list::create_rule(), iuse::crowbar(), salvage_actor::cut_up(), damage_item(), deactivate(), item_location::impl::item_in_container::describe(), iexamine::dimensional_portal(), iuse::directional_hologram(), display_money(), display_name(), iuse::dive_tank(), npc::do_reload(), draw_bionics_titlebar(), npc::drop_items(), drop_on_map(), drop_or_embed_projectile(), avatar_action::eat(), Character::eat(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), npc::execute_action(), Character::extended_description(), iuse::eyedrops(), Character::feed_furnace_with(), fetch_activity(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), npc::find_item(), heal_actor::finish_using(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), iuse::firecracker_act(), iexamine::fireplace(), iuse::fishing_rod(), iuse::flumed(), iuse::flusleep(), character_funcs::fmt_wielded_weapon(), Character::fuel_bionic_with(), iexamine::fvat_empty(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), generic_multi_activity_do(), avatar::get_book_reader(), get_continue_reqs(), get_encumber_when_containing(), get_making(), get_next_failure_point(), get_owner_name(), get_property_int64_t(), get_remaining_capacity_for_liquid(), vehicle::get_targeting_npc(), talk_function::give_equipment(), monexamine::give_items_to(), iuse::granade_act(), iuse::gun_repair(), avatar_funcs::gunmod_add(), activity_handlers::gunmod_add_finish(), avatar_funcs::gunmod_remove(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), repair_item_actor::handle_components(), handle_craft_failure(), ranged::handle_gun_damage(), liquid_handler::handle_liquid(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), auto_pickup::player_settings::has_rule(), npc::heal_self(), Character::i_add_to_container(), Character::i_rem(), ideal_ranged_dps(), iuse_transform::info(), info(), Character::invoke_item(), avatar::invoke_item(), advanced_inventory_pane::is_filtered(), Character::item_reload_cost(), npc::item_whitelisted(), iuse::jackhammer(), iexamine::keg(), game::list_items(), aim_activity_actor::load_RAS_weapon(), iuse::magic_8_ball(), marloss_common(), iuse::marloss_seed(), character_martial_arts::martialart_use_message(), iuse::meditate(), iuse::melatonin_tablet(), Character::melee_special_effects(), activity_handlers::mend_item_finish(), iuse::mind_splicer(), mod_charges(), mod_last_rot_check(), Character::modify_morale(), iuse::molotov_lit(), npc::mug_player(), iuse::multicooker(), Character::mutation_effect(), npc_throw(), on_wield(), iuse::oxygen_bottle(), iuse::pack_item(), target_ui::panel_gun_info(), parse_tags(), petfood(), pick_one_up(), iuse::pickaxe(), iuse::play_game(), avatar_action::plthrow(), iuse::portable_game(), Character::pour_into(), iexamine::pour_into_keg(), npc::pretend_fire(), game::print_items_info(), game::process_artifact(), process_blackpowder_fouling(), process_extinguish(), map::process_fields_in_submap(), process_internal(), process_litcig(), process_tool(), ranged::prompt_select_default_ammo_for(), mattack::pull_metal_weapon(), put_into_vehicle(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), character_funcs::rate_sleep_spot(), player::reduce_charges(), avatar_action::reload(), bandolier_actor::reload(), reload(), activity_handlers::reload_finish(), remove_radio_mod(), auto_pickup::player_settings::remove_rule(), repair_item_actor::repair(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), map::rotten_item_spawn(), iuse::rpgdie(), examine_item_menu::run(), iuse::seed(), character_funcs::select_ammo(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), set_item_inventory(), set_item_map(), set_item_map_or_vehicle(), set_mtype(), set_next_failure_point(), talk_effect_fun_t::set_u_buy_item(), gun_actor::shoot(), trading_window::show_item_data(), sleep(), smash(), iuse::smoking(), iuse::solarpack(), holster_actor::store(), npc::stow_item(), Character::suffer_from_bad_bionics(), monexamine::take_items_from(), Character::takeoff(), iuse::talking_doll(), tname(), iuse::toggle_heats_food(), tool_info(), iuse::towel_common(), iexamine::tree_maple_tapped(), try_consume(), avatar_funcs::try_disarm_npc(), try_reject_mutagen(), avatar_funcs::try_steal_from_npc(), salvage_actor::try_to_cut_up(), target_ui::uitext_title(), iuse::unfold_generic(), avatar_funcs::unload_item(), iuse::unpack_item(), Character::unwield(), inventory_entry::update_cache(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), set_transform_iuse::use(), change_scent_iuse::use(), deploy_furn_actor::use(), reveal_map_actor::use(), firestarter_actor::use(), inscribe_actor::use(), holster_actor::use(), ammobelt_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), saw_barrel_actor::use(), saw_stock_actor::use(), unpack_actor::use(), cast_spell_actor::use(), heal_actor::use_healing_item(), avatar_funcs::use_item(), npc::use_painkiller(), iuse::vibe(), activity_handlers::vibe_do_turn(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), avatar_action::wield(), Character::will_eat(), wind_resist(), debug_menu::wishitem(), memorial_logger::write(), and iuse::xanax().

◆ tool_info()

void item::tool_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3103 of file item.cpp.

3105{
3106 if( !is_tool() ) {
3107 return;
3108 }
3109
3111 if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CHARGES ) ) {
3112 info.emplace_back( "TOOL", string_format( _( "<bold>Charges</bold>: %d" ),
3113 ammo_remaining() ) );
3114 }
3115
3116 if( !magazine_integral() ) {
3118 info.emplace_back( "TOOL", _( "Magazine: " ),
3119 string_format( "<stat>%s</stat>", magazine_current()->tname() ) );
3120 }
3121
3123 const std::set<itype_id> compat = magazine_compatible();
3124 info.emplace_back( "TOOL", _( "Compatible magazines: " ),
3125 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
3126 return item::nname( id );
3127 } ) );
3128 }
3129 } else if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CAPACITY ) ) {
3130 std::string tmp;
3131 bool bionic_tool = has_flag( flag_USES_BIONIC_POWER );
3132 if( !ammo_types().empty() ) {
3133 //~ "%s" is ammunition type. This types can't be plural.
3134 tmp = vgettext( "Maximum <num> charge of %s.", "Maximum <num> charges of %s.",
3135 ammo_capacity() );
3136 tmp = string_format( tmp, enumerate_as_string( ammo_types().begin(),
3137 ammo_types().end(), []( const ammotype & at ) {
3138 return at->name();
3140
3141 // No need to display max charges, since charges are always equal to bionic power
3142 } else if( !bionic_tool ) {
3143 tmp = vgettext( "Maximum <num> charge.", "Maximum <num> charges.", ammo_capacity() );
3144 }
3145 if( !bionic_tool ) {
3146 info.emplace_back( "TOOL", "", tmp, iteminfo::no_flags, ammo_capacity() );
3147 }
3148 }
3149}

References _, ammo_capacity(), ammo_remaining(), ammo_types(), enumerate_as_string(), flag_USES_BIONIC_POWER(), has_flag(), info(), insert_separation_line(), is_tool(), magazine_compatible(), magazine_current(), magazine_integral(), ammunition_type::name(), iteminfo::no_flags, none, string_format(), iteminfo_query::test(), tname(), TOOL_CAPACITY, TOOL_CHARGES, TOOL_MAGAZINE_COMPATIBLE, TOOL_MAGAZINE_CURRENT, and vgettext().

Referenced by info().

◆ toolmods() [1/2]

std::vector< item * > item::toolmods ( )

Returns all toolmods currently attached to this item (always empty if item not a tool)

Definition at line 5476 of file item.cpp.

5477{
5478 std::vector<item *> res;
5479 if( is_tool() ) {
5480 for( item *e : contents.all_items_top() ) {
5481 if( e->is_toolmod() ) {
5482 res.push_back( e );
5483 }
5484 }
5485 }
5486 return res;
5487}

References item_contents::all_items_top(), contents, and is_tool().

Referenced by ammo_capacity(), ammo_data(), ammo_types(), contents_info(), has_flag(), magazine_compatible(), magazine_default(), magazine_integral(), iuse::remove_all_mods(), tname(), and iuse::toolmod_attach().

◆ toolmods() [2/2]

std::vector< const item * > item::toolmods ( ) const

Definition at line 5489 of file item.cpp.

5490{
5491 std::vector<const item *> res;
5492 if( is_tool() ) {
5493 for( const item *e : contents.all_items_top() ) {
5494 if( e->is_toolmod() ) {
5495 res.push_back( e );
5496 }
5497 }
5498 }
5499 return res;
5500}

References item_contents::all_items_top(), contents, and is_tool().

◆ type_name()

std::string item::type_name ( unsigned int  quantity = 1) const

Name of the item type (not the item), with proper plural.

This is only special when the item itself has a special name ("name" entry in item_tags) or is a named corpse. It's effectively the same as calling nname with the item type id. Use this when the actual item is not meant, for example "The shovel" instead of "Your shovel". Or "The jacket is too small", when it applies to all jackets, not just the one the character tried to wear).

Definition at line 9858 of file item.cpp.

9859{
9860 const auto iter = item_vars.find( "name" );
9861 std::string ret_name;
9862 if( typeId() == itype_blood ) {
9863 if( corpse == nullptr || corpse->id.is_null() ) {
9864 return vpgettext( "item name", "human blood", "human blood", quantity );
9865 } else {
9866 return string_format( vpgettext( "item name", "%s blood",
9867 "%s blood", quantity ),
9868 corpse->nname() );
9869 }
9870 } else if( iter != item_vars.end() ) {
9871 return iter->second;
9872 } else {
9873 ret_name = type->nname( quantity );
9874 }
9875
9876 // Apply conditional names, in order.
9877 for( const conditional_name &cname : type->conditional_names ) {
9878 // Lambda for recursively searching for a item ID among all components.
9879 std::function<bool ( std::list<item> )> component_id_contains =
9880 [&]( std::list<item> components ) {
9881 for( const item &component : components ) {
9882 if( component.typeId().str().find( cname.condition ) != std::string::npos ||
9883 component_id_contains( component.components ) ) {
9884 return true;
9885 }
9886 }
9887 return false;
9888 };
9889 switch( cname.type ) {
9891 if( has_flag( cname.condition ) ) {
9892 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9893 }
9894 break;
9896 if( component_id_contains( components ) ) {
9897 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9898 }
9899 break;
9901 break;
9902 }
9903 }
9904
9905 // Identify who this corpse belonged to, if applicable.
9906 if( corpse != nullptr && has_flag( flag_CORPSE ) ) {
9907 if( corpse_name.empty() ) {
9908 //~ %1$s: name of corpse with modifiers; %2$s: species name
9909 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of a %2$s" ),
9910 ret_name, corpse->nname() );
9911 } else {
9912 //~ %1$s: name of corpse with modifiers; %2$s: proper name; %3$s: species name
9913 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of %2$s, %3$s" ),
9914 ret_name, corpse_name, corpse->nname() );
9915 }
9916 }
9917
9918 return ret_name;
9919}
@ COMPONENT_ID
Definition: itype.h:778
@ FLAG
Definition: itype.h:777
@ num_condition_types
Definition: itype.h:779
std::string condition
Definition: itype.h:792
translation name
Definition: itype.h:795
condition_type type
Definition: itype.h:790
std::vector< conditional_name > conditional_names
Definition: itype.h:889

References COMPONENT_ID, components, conditional_name::condition, itype::conditional_names, corpse, corpse_name, FLAG, flag_CORPSE(), has_flag(), mtype::id, string_id< T >::is_null(), item_vars, itype_blood, conditional_name::name, itype::nname(), mtype::nname(), num_condition_types, pgettext(), string_format(), translation::translated(), type, conditional_name::type, typeId(), and vpgettext().

Referenced by advanced_inventory::action_examine(), Character::can_wear(), game_menus::inv::compare(), avatar::do_read(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), npc::finish_read(), character_funcs::fmt_wielded_weapon(), trading_window::get_var_trade(), Character::is_snuggling(), inscribe_actor::item_inscription(), label(), game::list_items(), Character::pour_into(), avatar::read(), bandolier_actor::reload(), game_menus::inv::repair(), examine_item_menu::run(), trading_window::show_item_data(), skim_book_msg(), Character::suffer_from_schizophrenia(), tname(), consume_drug_iuse::use(), place_monster_iuse::use(), and bandolier_actor::use().

◆ typeId()

const itype_id & item::typeId ( ) const

return the unique identifier of the items underlying type

Definition at line 8359 of file item.cpp.

8360{
8361 return type ? type->get_id() : itype_id::NULL_ID();
8362}

References itype::get_id(), string_id< itype >::NULL_ID(), and type.

Referenced by computer_session::action_blood_anal(), computer_session::action_data_anal(), add_disassemblables(), inventory::add_item_by_items_type_cache(), map::add_item_or_charges(), add_rain_to_container(), item_pricing::adjust_values(), vehicle_part::ammo_current(), ammo_set(), amount_of_internal(), armor_fit_info(), inventory::assign_empty_invlet(), iexamine::autodoc(), basic_info(), iuse::bell(), mattack::bio_op_takedown(), book_info(), Character::can_fuel_bionic_with(), vehicle_part::can_reload(), bandolier_actor::can_store(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), color_in_inventory(), combat_info(), crafting::complete_disassemble(), Character::compute_nutrient_range(), prepared_item_consumption::consume(), vehicle_part::consume_energy(), consumption_event::consumption_event(), mattack::copbot(), map::create_burnproducts(), iuse::directional_antenna(), disassembly_info(), Character::dismount(), iuse::dive_tank(), avatar::do_read(), npc::do_reload(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), editmap::draw_main_ui_overlay(), iuse::ecig(), iuse::ehandcuffs(), explosion_handler::emp_blast(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), farm_valid_seed(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), character_funcs::find_ammo_helper(), iexamine::fireplace(), food_info(), Character::fuel_bionic_with(), Character::fun_for(), iexamine::fvat_empty(), iuse::geiger(), json_talk_topic::gen_responses(), generic_multi_activity_do(), Character::get_acquirable_energy(), inventory::get_binned_items(), Character::get_bionic_fueled_with(), character_funcs::get_book_fun_for(), read_inventory_preset::get_denial(), bionic_install_preset::get_failure_chance(), Character::get_overlay_ids(), disassemble_inventory_preset::get_recipe(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), get_uncraft_components(), give_item_to(), mattack::grab(), iuse::granade_act(), Character::has_active_item(), inventory::has_enough_painkiller(), Character::i_add(), Character::i_add_to_container(), monster::init_from_item(), init_memory_card_with_random_stuff(), io(), advanced_inv_area::is_container_valid(), character_funcs::is_fun_to_read(), is_funnel_container(), is_gunmod_compatible(), read_inventory_preset::is_known(), is_null(), is_reloadable_helper(), ma_requirements::is_valid_character(), item(), Character::item_handling_cost(), iexamine::keg(), ma_style_callback::key(), aim_activity_actor::load_RAS_weapon(), iuse::lumber(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), to_cbc_migration::migration_required(), iuse::mind_splicer(), Item_modifier::modify(), advanced_inventory::move_content(), iuse::mp3(), iuse::mp3_on(), item_stack::only_item(), iuse::pack_cbm(), iuse::pack_item(), iexamine::pedestal_temple(), iexamine::pedestal_wyrm(), peek_related_recipe(), pick_usb(), avatar_action::plthrow(), iexamine::pour_into_keg(), process_extinguish(), process_litcig(), examine_item_menu::rate_action_disassemble(), examine_item_menu::rate_action_read(), avatar::read(), game_menus::inv::reassign_letter(), reload(), activity_handlers::reload_finish(), repair_item_actor::repair_recipe_difficulty(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), advanced_inv_area::set_container(), talk_effect_fun_t::set_remove_item_with(), player_morale::set_worn(), iuse::smoking(), iuse::solarpack(), iuse::solarpack_off(), Character::suffer_from_bad_bionics(), Character::suffer_from_radiation(), iuse::talking_doll(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), disassemble_activity_actor::try_start_single(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), type_name(), iuse::unpack_item(), inventory::update_cache_with_item(), inventory::update_invlet(), unfold_vehicle_iuse::use(), musical_instrument_actor::use(), unpack_actor::use(), use_amount_internal(), map::use_amount_square(), Character::use_charges(), map::use_charges(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), vehicle_part::vehicle_part(), volume(), iuse::water_purifier(), martialart::weapon_valid(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), npc::wield_better_weapon(), and wind_resist().

◆ units_remaining()

int item::units_remaining ( const Character ch,
int  limit = INT_MAX 
) const

How many units (ammo or charges) are remaining?

Parameters
chcharacter responsible for invoking the item
limitstop searching after this many units found
Note
also checks availability of UPS charges if applicable

Definition at line 7993 of file item.cpp.

7994{
7995 if( count_by_charges() ) {
7996 return std::min( static_cast<int>( charges ), limit );
7997 }
7998
7999 int res = ammo_remaining();
8000 if( res < limit && is_power_armor() ) {
8002 res += std::max( ch.charges_of( itype_UPS, limit - res ), ch.charges_of( itype_bio_armor,
8003 limit - res ) );
8004 } else if( character_funcs::can_interface_armor( ch ) ) {
8005 res += ch.charges_of( itype_bio_armor, limit - res );
8006 } else {
8007 res += ch.charges_of( itype_UPS, limit - res );
8008 }
8009 } else if( res < limit && has_flag( flag_USE_UPS ) ) {
8010 res += ch.charges_of( itype_UPS, limit - res );
8011 }
8012
8013 return std::min( static_cast<int>( res ), limit );
8014}
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:947

References ammo_remaining(), character_funcs::can_interface_armor(), charges, visitable< T >::charges_of(), count_by_charges(), flag_USE_UPS(), has_flag(), is_power_armor(), itype_bio_armor, and itype_UPS.

Referenced by iuse::portable_game(), units_sufficient(), iuse_transform::use(), and set_transform_iuse::use().

◆ units_sufficient()

bool item::units_sufficient ( const Character ch,
int  qty = -1 
) const

Check if item has sufficient units (ammo or charges) remaining.

Parameters
chCharacter to check (used if ammo is UPS charges)
qtyunits required, if unspecified use item default

Definition at line 8016 of file item.cpp.

8017{
8018 if( qty < 0 ) {
8019 qty = count_by_charges() ? 1 : ammo_required();
8020 }
8021
8022 return units_remaining( ch, qty ) == qty;
8023}
int units_remaining(const Character &ch, int limit=INT_MAX) const
How many units (ammo or charges) are remaining?
Definition: item.cpp:7993

References ammo_required(), count_by_charges(), and units_remaining().

Referenced by cauterize_actor::can_use(), iuse::gun_repair(), iuse::mp3(), iuse::multicooker(), iuse::noise_emitter_off(), iuse::radglove(), iuse::radio_off(), iuse::radiocontrol(), iuse::remoteveh(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), iuse::talking_doll(), iuse::tazer(), toolweapon_off(), toolweapon_on(), iuse::vibe(), and iuse::water_purifier().

◆ unset_flag()

item & item::unset_flag ( const std::string &  flag)

◆ unset_flags()

void item::unset_flags ( )

Removes all item specific flags.

Definition at line 5315 of file item.cpp.

5316{
5317 item_tags.clear();
5318}

References item_tags.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ update_clothing_mod_val()

void item::update_clothing_mod_val ( )

Definition at line 10172 of file item.cpp.

10173{
10175 float tmp = 0.0;
10176 for( const clothing_mod &cm : clothing_mods::get_all_with( type ) ) {
10177 if( has_own_flag( cm.flag ) ) {
10178 tmp += cm.get_mod_val( type, *this );
10179 }
10180 }
10182 }
10183}
clothing_mod_type
Definition: clothing_mod.h:16
const std::vector< clothing_mod > & get_all_with(clothing_mod_type type)
constexpr std::array< clothing_mod_type, 9 > all_clothing_mod_types
Definition: clothing_mod.h:63

References clothing_mods::all_clothing_mod_types, clothing_mods::get_all_with(), anonymous_namespace{item.cpp}::get_clothing_mod_val_key(), has_own_flag(), set_var(), and type.

Referenced by sew_advanced_actor::use().

◆ use_amount()

bool item::use_amount ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consume a specific amount of items of a specific type.

This includes this item, and any of its contents (recursively).

See also
item::use_charges - this is similar for items, not charges.
Parameters
itType of consumable item.
quantityHow much to consumed.
usedOn success all consumed items will be stored here.
filterMust return true for use to occur.

Definition at line 8497 of file item.cpp.

8499{
8500 // Remember quantity so that we can unseal self
8501 int old_quantity = quantity;
8502 std::vector<item *> removed_items;
8503 // First, check contents
8505 [&]( item * a ) {
8506 // visit_items checks the item itself first. we want to do its contents first.
8507 if( a == this ) {
8508 return VisitResponse::NEXT;
8509 }
8510 if( a->use_amount_internal( it, quantity, used, filter ) ) {
8511 removed_items.emplace_back( a );
8512 return VisitResponse::SKIP;
8513 }
8514 return VisitResponse::NEXT;
8515 } );
8516
8517 for( item *remove : removed_items ) {
8518 remove_item( *remove );
8519 }
8520
8521 if( quantity != old_quantity ) {
8523 }
8524 return use_amount_internal( it, quantity, used, filter );
8525}
bool use_amount_internal(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: item.cpp:8527
constexpr double a
Definition: magic.cpp:1030

References a, NEXT, on_contents_changed(), visitable< item >::remove_item(), use_amount_internal(), and visitable< item >::visit_items().

◆ use_amount_internal()

bool item::use_amount_internal ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)
private

Definition at line 8527 of file item.cpp.

8529{
8530 if( typeId() == it && quantity > 0 && filter( *this ) ) {
8531 used.push_back( *this );
8532 quantity--;
8533 return true;
8534 } else {
8535 return false;
8536 }
8537}

References typeId().

Referenced by use_amount().

◆ use_charges()

bool item::use_charges ( const itype_id what,
int &  qty,
std::list< item > &  used,
const tripoint pos,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consumes specified charges (or fewer) from this and any contained items.

Parameters
whatspecific type of charge required, e.g. 'battery'
qtymaximum charges to consume. On return set to number of charges not found (or zero)
usedfilled with duplicates of each item that provided consumed charges
posposition at which the charges are being consumed
filterMust return true for use to occur.
Returns
true if this item should be deleted (count-by-charges items with no remaining charges)

Definition at line 8617 of file item.cpp.

8619{
8620 std::vector<item *> del;
8621
8622 visit_items( [&what, &qty, &used, &pos, &del, &filter]( item * e, item * parent ) {
8623 if( qty == 0 ) {
8624 // found sufficient charges
8625 return VisitResponse::ABORT;
8626 }
8627
8628 if( !filter( *e ) ) {
8629 return VisitResponse::NEXT;
8630 }
8631
8632 if( e->is_tool() ) {
8633 if( e->typeId() == what ) {
8634 int n = std::min( e->ammo_remaining(), qty );
8635 qty -= n;
8636
8637 used.push_back( item( *e ).ammo_set( e->ammo_current(), n ) );
8638 e->ammo_consume( n, pos );
8639 }
8640 return VisitResponse::SKIP;
8641
8642 } else if( e->count_by_charges() ) {
8643 if( e->typeId() == what ) {
8644
8645 // if can supply excess charges split required off leaving remainder in-situ
8646 item obj = e->split( qty );
8647 if( parent ) {
8648 parent->on_contents_changed();
8649 }
8650 if( !obj.is_null() ) {
8651 used.push_back( obj );
8652 qty = 0;
8653 return VisitResponse::ABORT;
8654 }
8655
8656 qty -= e->charges;
8657 used.push_back( *e );
8658 del.push_back( e );
8659 }
8660 // items counted by charges are not themselves expected to be containers
8661 return VisitResponse::SKIP;
8662 }
8663
8664 // recurse through any nested containers
8665 return VisitResponse::NEXT;
8666 } );
8667
8668 bool destroy = false;
8669 for( item *e : del ) {
8670 if( e == this ) {
8671 destroy = true; // cannot remove ourselves...
8672 } else {
8673 remove_item( *e );
8674 }
8675 }
8676
8677 return destroy;
8678}

References ABORT, count_by_charges(), is_tool(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by Character::use_charges(), and use_charges_from_furn().

◆ validate_ownership()

void item::validate_ownership ( ) const

Definition at line 1296 of file item.cpp.

1297{
1298 if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
1300 }
1301 if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
1302 remove_owner();
1303 }
1304}
void remove_old_owner() const
Definition: item.h:2032
void remove_owner() const
Definition: item.h:2039

References g, string_id< T >::is_null(), old_owner, owner, remove_old_owner(), and remove_owner().

Referenced by get_old_owner(), and get_owner().

◆ volume()

units::volume item::volume ( bool  integral = false) const

Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge.

If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Parameters
integralif true return effective volume if this item was integrated into another

Definition at line 5131 of file item.cpp.

5132{
5133 if( is_null() ) {
5134 return 0_ml;
5135 }
5136
5137 if( is_corpse() ) {
5138 return corpse_volume( corpse );
5139 }
5140
5141 if( is_craft() ) {
5142 units::volume ret = 0_ml;
5143 for( const item &it : components ) {
5144 ret += it.volume();
5145 }
5146 return ret;
5147 }
5148
5149 const int local_volume = get_var( "volume", -1 );
5151 if( local_volume >= 0 ) {
5152 ret = local_volume * units::legacy_volume_factor;
5153 } else if( integral ) {
5155 } else {
5156 ret = type->volume;
5157 }
5158
5159 if( count_by_charges() || made_of( LIQUID ) ) {
5161 ( charges );
5162 if( type->stack_size <= 0 ) {
5163 debugmsg( "Item type %s has invalid stack_size %d", typeId().str(), type->stack_size );
5164 ret = num;
5165 } else {
5166 ret = num / type->stack_size;
5167 if( num % type->stack_size != 0_ml ) {
5168 ret += 1_ml;
5169 }
5170 }
5171 }
5172
5173 // Non-rigid items add the volume of the content
5174 if( !type->rigid ) {
5176 }
5177
5178 // Some magazines sit (partly) flush with the item so add less extra volume
5179 if( magazine_current() != nullptr ) {
5180 ret += std::max( magazine_current()->volume() - type->magazine_well, 0_ml );
5181 }
5182
5183 if( is_gun() ) {
5184 for( const item *elem : gunmods() ) {
5185 ret += elem->volume( true );
5186 }
5187
5188 // TODO: implement stock_length property for guns
5190 // consider only the base size of the gun (without mods)
5191 ret -= ( type->volume / 3 );
5192 }
5193
5195 ret -= type->gun->barrel_length;
5196 }
5197 }
5198
5199 return ret;
5200}
static const std::string flag_COLLAPSIBLE_STOCK("COLLAPSIBLE_STOCK")
units::volume magazine_well
Volume above which the magazine starts to protrude from the item and add extra volume.
Definition: itype.h:997
units::volume integral_volume
Space consumed when integrated as part of another item (defaults to volume) CAUTION: value given is f...
Definition: itype.h:950

References charges, components, contents, corpse, corpse_volume(), count_by_charges(), debugmsg, flag_COLLAPSIBLE_STOCK(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_volume, is_corpse(), is_craft(), is_gun(), is_null(), item_contents::item_size_modifier(), itype_barrel_small, units::legacy_volume_factor, LIQUID, made_of(), magazine_current(), itype::magazine_well, num, cata::hash64_detail::ret, itype::rigid, itype::stack_size, type, typeId(), volume(), and itype::volume.

Referenced by activity_on_turn_move_loot(), map::add_item_or_charges(), ranged::aim_cap_from_volume(), attack_cost(), basic_info(), veh_interact::calc_overview(), holster_actor::can_holster(), charges_per_volume(), comestible_inventory_preset::comestible_inventory_preset(), vehicle_part::consume_energy(), Character::deal_damage(), npc::drop_items(), drop_or_embed_projectile(), fetch_activity(), iexamine::fvat_empty(), Character::get_acquirable_energy(), get_encumber_when_containing(), ranged::get_weapon_dispersion(), monexamine::give_items_to(), repair_item_actor::handle_components(), Character::item_handling_cost(), mdeath::jabberwock(), iexamine::keg(), Character::melee_special_effects(), move_cost_cart(), move_cost_inv(), iexamine::nanofab(), npc_pickup_from_stack(), pickup::obtain_and_tokenize_items(), Character::on_dodge(), on_wield(), vehicle::operate_scoop(), pick_one_up(), pickup::pick_up(), iexamine::pour_into_keg(), Character::power_rating(), process_corpse(), iuse::radiocar(), ready_to_revive(), pickup::reorder_for_dropping(), item_pricing::set_values(), npc::shop_restock(), smash(), holster_actor::store(), npc::stow_item(), stumble(), Character::takeoff(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), tname(), Character::update_bodytemp(), volume(), inventory::volume_without(), and wash_items().

◆ weight()

units::mass item::weight ( bool  include_contents = true,
bool  integral = false 
) const

Definition at line 4985 of file item.cpp.

4986{
4987 if( is_null() ) {
4988 return 0_gram;
4989 }
4990
4991 // Items that don't drop aren't really there, they're items just for ease of implementation
4992 if( has_flag( flag_NO_DROP ) ) {
4993 return 0_gram;
4994 }
4995
4996 if( is_craft() ) {
4997 units::mass ret = 0_gram;
4998 for( const item &it : components ) {
4999 ret += it.weight();
5000 }
5001 return ret;
5002 }
5003
5005 std::string local_str_mass = integral ? get_var( "integral_weight" ) : get_var( "weight" );
5006 if( local_str_mass.empty() ) {
5007 ret = integral ? type->integral_weight : type->weight;
5008 } else {
5009 ret = units::from_milligram( std::stoll( local_str_mass ) );
5010 }
5011
5012 if( has_flag( flag_REDUCED_WEIGHT ) ) {
5013 ret *= 0.75;
5014 }
5015
5016 // if this is a gun apply all of its gunmods' weight multipliers
5017 if( is_gun() ) {
5018 for( const item *mod : gunmods() ) {
5019 ret *= mod->type->gunmod->weight_multiplier;
5020 }
5021 }
5022
5023 if( count_by_charges() ) {
5024 ret *= charges;
5025
5026 } else if( is_corpse() ) {
5027 assert( corpse ); // To appease static analysis
5028 ret = corpse->weight;
5030 ret *= 0.75;
5031 }
5032 if( has_flag( flag_QUARTERED ) ) {
5033 ret /= 4;
5034 }
5035 if( has_flag( flag_GIBBED ) ) {
5036 ret *= 0.85;
5037 }
5038 if( has_flag( flag_SKINNED ) ) {
5039 ret *= 0.85;
5040 }
5041
5042 } else if( magazine_integral() && !is_magazine() ) {
5043 if( ammo_current() == itype_plut_cell ) {
5044 units::mass w = ( *ammo_types().begin() )->default_ammotype()->weight;
5046 } else if( ammo_data() ) {
5048 }
5049 }
5050
5051 // if this is an ammo belt add the weight of any implicitly contained linkages
5052 if( is_magazine() && type->magazine->linkage ) {
5053 item links( *type->magazine->linkage );
5054 links.charges = ammo_remaining();
5055 ret += links.weight();
5056 }
5057
5058 // reduce weight for sawn-off weapons capped to the apportioned weight of the barrel
5060 const units::volume b = type->gun->barrel_length;
5061 const units::mass max_barrel_weight = units::from_gram( to_milliliter( b ) );
5062 const units::mass barrel_weight = units::from_gram( b.value() * type->weight.value() /
5063 type->volume.value() );
5064 ret -= std::min( max_barrel_weight, barrel_weight );
5065 }
5066
5067 if( is_gun() ) {
5068 for( const item *elem : gunmods() ) {
5069 ret += elem->weight( true, true );
5070 }
5071 if( !magazine_integral() && magazine_current() ) {
5072 ret += std::max( magazine_current()->weight(), 0_gram );
5073 }
5074 } else if( include_contents ) {
5076 }
5077
5078 return ret;
5079}
units::mass item_weight_modifier() const
static const std::string flag_NO_DROP("NO_DROP")
static const std::string flag_REDUCED_WEIGHT("REDUCED_WEIGHT")
static const itype_id itype_plut_cell("plut_cell")
constexpr double b
Definition: magic.cpp:1031
constexpr value_type to_milliliter(const quantity< value_type, volume_in_milliliter_tag > &v)
Definition: units_volume.h:38
constexpr quantity< value_type, mass_in_milligram_tag > from_milligram(const value_type v)
Definition: units_mass.h:34
constexpr quantity< value_type, mass_in_milligram_tag > from_gram(const value_type v)
Definition: units_mass.h:41
units::mass integral_weight
Weight difference with the part it replaces for mods.
Definition: itype.h:938
units::mass weight
Definition: mtype.h:265

References ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), b, charges, components, contents, corpse, count_by_charges(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_NO_DROP(), flag_QUARTERED(), flag_REDUCED_WEIGHT(), flag_SKINNED(), units::from_gram(), units::from_milligram(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_weight, is_corpse(), is_craft(), is_gun(), is_magazine(), is_null(), item_contents::item_weight_modifier(), itype_barrel_small, itype_plut_cell, itype::magazine, magazine_current(), magazine_integral(), PLUTONIUM_CHARGES, cata::hash64_detail::ret, units::to_milliliter(), type, units::quantity< V, U >::value(), itype::volume, weight(), itype::weight, and mtype::weight.

Referenced by monexamine::add_armor(), attack_cost(), basic_info(), can_do_activity_there(), holster_actor::can_holster(), Character::can_pick_weight(), veh_interact::can_remove_part(), pickup::cost_to_move_item(), salvage_actor::cut_up(), npc::drop_items(), fetch_activity(), funnel_charges_per_turn(), Character::get_acquirable_energy(), Character::get_weight(), monexamine::give_items_to(), is_two_handed(), lift_strength(), Character::melee_attack(), minimal_weight_to_cut(), npc_pickup_from_stack(), pick_one_up(), pickup::pick_up(), advanced_inventory::query_charges(), iuse::radiocar(), item_pricing::set_values(), smash(), holster_actor::store(), stumble(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), salvage_actor::time_to_cut_up(), trap::triggered_by_item(), salvage_actor::try_to_cut_up(), veh_interact::update_part_requirements(), salvage_actor::valid_to_cut_up(), weight(), Character::weight_carried_reduced_by(), and inventory::weight_without().

◆ wheel_area()

int item::wheel_area ( ) const

Returns the total area of this wheel or 0 if it isn't one.

Definition at line 6821 of file item.cpp.

6822{
6823 return is_wheel() ? type->wheel->diameter * type->wheel->width : 0;
6824}

References is_wheel(), type, and itype::wheel.

◆ will_explode_in_fire()

bool item::will_explode_in_fire ( ) const

Definition at line 8735 of file item.cpp.

8736{
8737 if( type->explode_in_fire ) {
8738 return true;
8739 }
8740
8741 if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8742 return true;
8743 }
8744
8745 // Most containers do nothing to protect the contents from fire
8746 if( !is_magazine() || !type->magazine->protects_contents ) {
8747 return has_item_with( [&]( const item & it ) {
8748 return this != &it && it.will_explode_in_fire();
8749 } );
8750 }
8751
8752 return false;
8753}
bool will_explode_in_fire() const
Definition: item.cpp:8735
bool explode_in_fire
Definition: itype.h:918

References itype::ammo, itype::explode_in_fire, visitable< item >::has_item_with(), is_magazine(), itype::magazine, type, and will_explode_in_fire().

Referenced by will_explode_in_fire().

◆ wind_resist()

int item::wind_resist ( ) const

How resistant clothes made of this material are to wind (0-100)

Definition at line 6790 of file item.cpp.

6791{
6792 std::vector<const material_type *> materials = made_of_types();
6793 if( materials.empty() ) {
6794 debugmsg( "Called item::wind_resist on an item (%s [%s]) made of nothing!", tname(), typeId() );
6795 return 99;
6796 }
6797
6798 int best = -1;
6799 for( const material_type *mat : materials ) {
6800 std::optional<int> resistance = mat->wind_resist();
6801 if( resistance && *resistance > best ) {
6802 best = *resistance;
6803 }
6804 }
6805
6806 // Default to 99% effective
6807 if( best == -1 ) {
6808 return 99;
6809 }
6810
6811 return best;
6812}

References debugmsg, made_of_types(), tname(), and typeId().

Referenced by wind_resistance_from_item_list().

Member Data Documentation

◆ activated_by

safe_reference<Character> item::activated_by

Definition at line 2248 of file item.h.

Referenced by detonate(), itype::invoke(), and explosion_iuse::use().

◆ active

bool item::active = false

Definition at line 2247 of file item.h.

Referenced by activate(), Character::activate_bionic(), map::add_item(), npc::alt_attack(), iexamine::autodoc(), basic_info(), burn(), iuse::c4(), iuse::cable_attach(), holster_actor::can_holster(), countdown_actor::can_use(), check_litcig(), color_in_inventory(), Character::consume_remote_fuel(), deactivate(), mdeath::detonate(), iuse::dive_tank(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), Character::find_remote_fuel(), iuse::firecracker(), iuse::firecracker_pack(), iuse::fish_trap(), iuse::gasmask(), iuse::geiger(), iuse::granade(), Character::has_active_item(), io(), enchantment::is_active(), item(), mattack::kamikaze(), make_gun_projectile(), activity_handlers::make_zlave_finish(), iuse::mininuke(), iuse::molotov_lit(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), needs_processing(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_takeoff(), on_wear(), iuse::pack_item(), process_extinguish(), process_internal(), process_litcig(), process_tool(), process_UPS(), process_wet(), vehicle_part::properties_to_item(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), read(), iuse::remoteveh(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), sleep(), iuse::smoking(), iuse::solarpack_off(), stacks_with(), holster_actor::store(), ranged::throw_item(), iuse::throwable_extinguisher_act(), tname(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), iuse::towel_common(), avatar_funcs::unload_item(), iuse::unpack_item(), iuse_transform::use(), countdown_actor::use(), fireweapon_off_actor::use(), musical_instrument_actor::use(), and npc::value().

◆ anchor

safe_reference_anchor item::anchor
private

Definition at line 2179 of file item.h.

Referenced by get_safe_reference().

◆ bday

time_point item::bday
private

The time the item was created.

Definition at line 2237 of file item.h.

Referenced by birthday(), io(), item(), legacy_fast_forward_time(), and set_birthday().

◆ burnt

int item::burnt = 0

◆ charges

int item::charges

Definition at line 2209 of file item.h.

Referenced by iuse::acidbomb_act(), act_vehicle_siphon(), Character::activate_bionic(), activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), add_rain_to_container(), ammo_consume(), vehicle_part::ammo_consume(), ammo_remaining(), vehicle_part::ammo_remaining(), ammo_set(), ammo_unset(), item_stack::amount_can_fit(), jmapgen_liquid_item::apply(), are_requirements_nearby(), iuse::arrow_flammable(), basic_info(), burn(), iuse::c4(), iuse::can_goo(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), veh_interact::complete_vehicle(), Character::consume_charges(), vehicle_part::consume_energy(), Character::consume_item(), liquid_handler::consume_liquid(), Character::consume_med(), game_menus::inv::container_for(), count(), activity_handlers::craft_do_turn(), recipe::create_byproducts(), recipe::create_result(), recipe::create_results(), detonate(), mdeath::detonate(), display_name(), iuse::dive_tank(), anonymous_namespace{iexamine.cpp}::atm_menu::do_purchase_card(), npc::do_reload(), veh_interact::do_siphon(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), map::draw_lab(), iuse::ehandcuffs(), explosion_handler::emp_blast(), iuse::eyedrops(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), wash_activity_actor::finish(), heal_actor::finish_using(), iuse::firecracker(), iuse::firecracker_act(), iuse::firecracker_pack(), iuse::firecracker_pack_act(), iuse::fish_trap(), character_funcs::fmt_wielded_weapon(), food_info(), for_each_item_in_both(), inventory::form_from_map(), Character::fuel_bionic_with(), funnel_charges_per_turn(), iexamine::fvat_empty(), iexamine::fvat_full(), iuse::gasmask(), Character::get_acquirable_energy(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iexamine::get_harvest_items(), liquid_handler::get_liquid_target(), get_remaining_capacity_for_liquid(), inventory_entry::get_selected_charges(), json_item_substitution::get_substitution(), monexamine::give_items_to(), iuse::granade(), iuse::granade_act(), iuse::grenade_inc_act(), hackveh(), liquid_handler::handle_all_liquid(), liquid_handler::handle_liquid_from_container(), pickup::handle_spillable_contents(), has_infinite_charges(), Character::i_add_to_container(), io(), item(), Character::item_reload_cost(), iexamine::keg(), med_info(), merge_charges(), Item_factory::migrate_item(), activity_handlers::milk_finish(), iuse::mininuke(), mod_charges(), mod_damage(), Item_modifier::modify(), iuse::molotov_lit(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_throw(), vehicle::operate_planter(), operator<(), parse_tags(), iexamine::pay_gas(), liquid_handler::perform_liquid_transfer(), pick_one_up(), pickup::pick_up(), map::place_gas_pump(), map::place_toilet(), Character::pour_into(), iexamine::pour_into_keg(), advanced_inventory::print_items(), game::process_artifact(), process_cable(), Character::process_items(), relic_funcs::process_recharge_entry(), map::produce_sap(), vehicle_part::properties_to_item(), item_reload_option::qty(), advanced_inventory::query_charges(), player::reduce_charges(), bandolier_actor::reload(), reload(), remove_ammo(), reset_cable(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_countdown(), iexamine::sign(), character_funcs::siphon(), smoker_activate(), map::spawn_an_item(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::suffer_from_bad_bionics(), iuse::tazer2(), Character::throw_range(), iuse::throwable_extinguisher_act(), ranged::throwing_dispersion(), tname(), npc_trading::trade(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), try_consume(), try_fuel_fire(), units_remaining(), avatar_funcs::unload_item(), inventory::update_quality_cache(), explosion_iuse::use(), place_monster_iuse::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), bandolier_actor::use(), emit_actor::use(), sew_advanced_actor::use(), basecamp::use_charges(), map::use_charges(), use_charges_from_furn(), iexamine::use_furn_fake_item(), volume(), iuse::water_purifier(), weight(), Character::weight_carried_reduced_by(), debug_menu::wishitem(), and memorial_logger::write().

◆ components

◆ contents

item_contents item::contents

Definition at line 2171 of file item.h.

Referenced by Character::absorb_hit(), act_vehicle_siphon(), computer_session::action_blood_anal(), computer_session::action_data_anal(), actualize_rot(), vehicle::add_item(), add_rain_to_container(), allow_crafting_component(), ammo_consume(), vehicle_part::ammo_consume(), vehicle_part::ammo_current(), ammo_data(), ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), map::bash_items(), iuse::blood_draw(), activity_handlers::butcher_finish(), item_location::impl::item_in_container::calc_index(), veh_interact::calc_overview(), item_funcs::can_be_unloaded(), Character::can_consume(), can_holster(), bandolier_actor::can_store(), can_unload_liquid(), casings_handle(), complete_craft(), veh_interact::complete_vehicle(), Character::compute_nutrient_range(), Character::consume(), npc::consume_cbm_items(), vehicle_part::consume_energy(), contents_info(), contents_made_of(), salvage_actor::cut_up(), damage_item(), item_location::deserialize(), deserialize(), detonate(), display_name(), veh_interact::do_siphon(), avatar_action::eat(), empty_buckets(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), fill_with(), final_info(), character_funcs::find_ammo_helper(), character_funcs::fmt_wielded_weapon(), get_category(), Character::get_consumable_from(), get_contained(), get_encumber(), get_free_mod_locations(), liquid_handler::get_liquid_target(), get_quality(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), trading_window::get_var_trade(), goes_bad_after_opening(), gunmods(), liquid_handler::handle_liquid_from_container(), Character::handle_melee_wear(), handle_problematic_pickup(), pickup::handle_spillable_contents(), has_effect_when_carried(), Character::i_add_to_container(), info(), is_ammo_container(), is_container_empty(), is_container_full(), advanced_inv_area::is_container_valid(), is_dangerous(), is_food_container(), is_funnel_container(), is_med_container(), is_reloadable_helper(), item_has_uses_recursive(), Character::item_reload_cost(), magazine_current(), item_location::impl::item_in_container::make_dirty(), Character::melee_special_effects(), Item_factory::migrate_item(), activity_handlers::mind_splicer_finish(), advanced_inventory::move_content(), iuse::multicooker(), needs_processing(), on_pickup(), operator<(), peek_related_recipe(), put_in(), item_reload_option::qty(), qualities_info(), iuse::radiocar(), avatar_action::reload(), bandolier_actor::reload(), reload(), item_contents::remove_internal(), visitable< T >::remove_items_with(), character_funcs::select_ammo(), serialize(), advanced_inv_area::set_container(), map::smash_items(), spill_contents(), spoilage_sort_order(), stacks_with(), tname(), toolmods(), iexamine::tree_maple_tapped(), try_consume(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), avatar_funcs::unload_item(), item_location::impl::item_in_container::unpack(), holster_actor::use(), bandolier_actor::use(), salvage_actor::valid_to_cut_up(), visit_internal(), volume(), iuse::water_purifier(), weight(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and memorial_logger::write().

◆ corpse

◆ corpse_name

std::string item::corpse_name
private

Definition at line 2183 of file item.h.

Referenced by get_corpse_name(), io(), and type_name().

◆ craft_data_

◆ curammo

const itype* item::curammo = nullptr
private

Definition at line 2180 of file item.h.

Referenced by ammo_consume(), ammo_data(), ammo_set(), ammo_unset(), gun_info(), io(), and reload().

◆ damage_

int item::damage_ = 0
private

Definition at line 2242 of file item.h.

Referenced by basic_info(), damage(), damage_level(), io(), mod_damage(), on_damage(), set_damage(), and stacks_with().

◆ drop_token

pimpl<item_drop_token> item::drop_token

Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class.

Definition at line 2260 of file item.h.

Referenced by pickup::obtain_and_tokenize_items(), and pickup::optimize_pickup().

◆ encumbrance_update_

bool item::encumbrance_update_ = false

Definition at line 2225 of file item.h.

Referenced by on_contents_changed().

◆ energy

units::energy item::energy

Definition at line 2210 of file item.h.

Referenced by energy_remaining(), io(), mod_energy(), and process_tool().

◆ faults

◆ frequency

int item::frequency = 0

Definition at line 2215 of file item.h.

Referenced by io(), and iuse::radio_on().

◆ INFINITE_CHARGES

◆ invlet

◆ irradiation

int item::irradiation = 0

Definition at line 2217 of file item.h.

Referenced by armor_fit_info(), and io().

◆ is_favorite

◆ item_counter

◆ item_tags

◆ item_vars

std::map<std::string, std::string> item::item_vars
private

◆ last_rot_check

time_point item::last_rot_check = calendar::turn_zero
private

Time when the rot calculation was last performed.

Definition at line 2235 of file item.h.

Referenced by basic_info(), io(), item(), legacy_fast_forward_time(), mod_last_rot_check(), process(), process_rot(), and set_relative_rot().

◆ light

light_emission item::light = nolight
private

Definition at line 2243 of file item.h.

Referenced by getlight(), io(), and is_emissive().

◆ mission_id

int item::mission_id = -1

◆ old_owner

faction_id item::old_owner = faction_id::NULL_ID()
mutableprivate

◆ owner

◆ player_id

int item::player_id = -1

Definition at line 2220 of file item.h.

Referenced by mission::deserialize(), io(), and mission::serialize().

◆ poison

◆ recipe_charges

int item::recipe_charges = 1

Definition at line 2212 of file item.h.

Referenced by complete_craft(), Character::compute_effective_nutrients(), and io().

◆ relic_data

◆ rot

time_duration item::rot = 0_turns
private

Accumulated rot, expressed as time the item has been in standard temperature.

It is compared to shelf life (islot_comestible::spoils) to decide if the item is rotten.

Definition at line 2233 of file item.h.

Referenced by basic_info(), minimum_freshness_duration(), spoilage_sort_order(), and stacks_with().

◆ snip_id

snippet_id item::snip_id = snippet_id::NULL_ID()

Definition at line 2216 of file item.h.

Referenced by basic_info(), io(), item(), and set_snippet().

◆ techniques

std::set<matec_id> item::techniques
private

Definition at line 2184 of file item.h.

Referenced by add_technique(), combat_info(), get_techniques(), has_technique(), io(), and stacks_with().

◆ type

const itype* item::type

Definition at line 2170 of file item.h.

Referenced by activate(), npc::activate_item(), actualize_rot(), game::add_artifact_dreams(), map::add_item(), add_monsters(), iuse::adrenaline_injector(), alcohol(), ammo_capacity(), ammo_data(), ammo_default(), ammo_effects(), ammo_required(), ammo_set(), ammo_type(), ammo_types(), iuse::antiasthmatic(), iuse::antibiotic(), iuse::anticonvulsant(), iuse::antifungal(), iuse::antiparasitic(), apply_lock_picking_tool(), armor_info(), armor_protection_info(), iuse::artifact(), iexamine::autodoc(), base_damage_thrown(), base_volume(), basic_info(), battery_info(), iuse::bell(), bionic_info(), talk_function::bionic_install(), iuse::blech(), iuse::blech_because_unclean(), iuse::blood_draw(), iuse::boltcutters(), book_info(), brewing_results(), brewing_time(), mdeath::broken(), burn(), Character::burn_fuel(), iuse::c4(), character_effects::calc_focus_equilibrium(), iuse::call_of_tindalos(), iuse::camera(), item_funcs::can_be_unloaded(), can_contain(), can_do_activity_there(), Character::can_eat(), iuse::can_goo(), can_holster(), npc::can_read(), Character::can_reload(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), install_bionic_actor::can_use(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), iuse::capture_monster_act(), charges_per_volume(), check_art_charge_req(), iuse::chew(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), color(), color_in_inventory(), combat_info(), common_ammo_default(), prepared_item_consumption::consume(), Character::consume_effects(), Character::consume_med(), iuse::contacts(), contain_monster(), container_info(), convert(), count_by_charges(), activity_handlers::cracking_do_turn(), Character::crit_chance(), iuse::crowbar(), damage_melee(), iuse::datura(), deactivate(), deserialize(), mission::deserialize(), player_morale::morale_point::deserialize(), addiction::deserialize(), vehicle::deserialize(), detonate(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), iuse::directional_hologram(), display_name(), iuse::dive_tank(), avatar::do_read(), iuse::dog_whistle(), game::dump_stats(), Character::eat(), mattack::eat_food(), iuse::ecig(), iuse::ehandcuffs(), iuse::einktabletpc(), emit_radio_signal(), engine_displacement(), Character::enumerate_unmet_requirements(), iuse::extinguisher(), iuse::eyedrops(), faults_potential(), talk_function::field_harvest(), iuse::fill_pit(), final_info(), find_armor_data(), find_best_lock_picking_tool(), npc::find_dangerous_explosives(), npc::finish_read(), heal_actor::finish_using(), avatar_action::fire_wielded_weapon(), iuse::firecracker(), iexamine::fireplace(), iuse::flumed(), iuse::flusleep(), iuse::foodperson(), fuel_energy(), fuel_pump_terrain(), iuse::fungicide(), iuse::gasmask(), iuse::geiger(), json_talk_topic::gen_responses(), Character::get_acquirable_energy(), activatable_inventory_preset::get_action_name(), bionic_install_preset::get_anesth_amount(), bionic_uninstall_preset::get_anesth_amount(), get_available_recipes(), get_base_env_resist(), get_base_env_resist_w_filter(), read_inventory_preset::get_book(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_category(), get_chapters(), get_clothing_mod_val(), get_comestible(), get_comestible_fun(), get_container_capacity(), activatable_inventory_preset::get_denial(), read_inventory_preset::get_denial(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), bionic_uninstall_preset::get_denial(), comestible_inventory_preset::get_edible_comestible(), get_encumber_when_containing(), get_env_resist(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), ranged::get_fastest_sight(), get_gun_ups_drain(), npc::get_healing_item(), Character::get_hit_weapon(), get_layer(), get_min_str(), get_mod_locations(), ranged::get_most_accurate_sight(), zone_manager::get_near_zone_type_for_item(), bionic_install_preset::get_operation_duration(), bionic_install_surgeon_preset::get_operation_duration(), bionic_uninstall_preset::get_operation_duration(), comestible_inventory_preset::get_order(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_plant_epoch(), get_plant_name(), get_property_int64_t(), get_property_string(), get_qualities(), get_quality(), get_reload_time(), get_remaining_capacity_for_liquid(), get_storage(), get_techniques(), get_thickness(), get_total_capacity(), get_use_internal(), plot_options::get_zone_name_suggestion(), getGasDiscountCardQuality(), getlight_emit(), goes_bad_after_opening(), iuse::granade(), iuse::granade_act(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), gun_recoil_multiplier(), iuse::gun_repair(), gun_skill(), npc_ai::gun_value(), gunmod_info(), avatar_funcs::gunmod_installation_odds(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::handle_ground_graffiti(), ranged::handle_gun_damage(), has_effect_when_carried(), has_effect_when_wielded(), has_effect_when_worn(), has_explosion_data(), has_flag(), npc::has_healing_options(), has_property(), has_technique(), has_use(), npc::heal_player(), npc::heal_self(), iuse::honeycomb(), in_its_container(), countdown_actor::info(), info(), iuse::inhaler(), inherit_flags(), Character::invoke_item(), avatar::invoke_item(), npc::invoke_item(), io(), is_ammo(), is_artifact(), is_bandolier(), is_battery(), is_bionic(), is_book(), is_brewable(), is_bucket(), is_container(), is_deployable(), is_emissive(), is_engine(), is_fuel(), is_gun(), is_gunmod(), is_holster(), is_magazine(), is_non_resealable_container(), is_null(), avatar_funcs::is_pet_food(), is_seed(), activatable_inventory_preset::is_shown(), is_tool(), is_toolmod(), is_transformable(), is_upgrade(), is_watertight_container(), is_wheel(), item(), item_has_uses_recursive(), Character::item_reload_cost(), item_reload_option::item_reload_option(), iuse::jackhammer(), iuse::jet_injector(), submap::load(), iuse::lumber(), iuse::ma_manual(), made_of(), magazine_compatible(), magazine_default(), magazine_info(), magazine_integral(), iuse::makemound(), mark_chapter_as_read(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), max_damage(), iuse::meditate(), Character::meets_requirements(), Character::meets_stat_requirements(), iuse::melatonin_tablet(), npc_ai::melee_value(), iuse::meth(), mill_load_food(), min_damage(), iuse::mind_splicer(), mine_activity(), minimum_freshness_duration(), iuse::mininuke(), mod_damage(), mod_energy(), Item_modifier::modify(), iuse::modify_grid_connections(), Character::modify_morale(), iuse::mop(), avatar_action::move(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), mutagen_common_checks(), iuse::mycus(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_contents_changed(), on_drop(), on_pickup(), on_takeoff(), on_wear(), on_wield(), operator<(), iuse::oxygen_bottle(), iuse::pheromone(), iuse::plantblech(), iuse::poison(), iuse::portal(), Character::pour_into(), price(), process(), game::process_artifact(), process_cable(), process_extinguish(), process_internal(), Character::process_items(), process_tool(), process_vehicle_items(), process_wet(), vehicle_part::properties_to_item(), iuse::prozac(), iuse::purifier(), iuse::purify_iv(), iuse::purify_smart(), item_reload_option::qty(), qualities_info(), quality_of(), plot_options::query_seed(), iuse::radglove(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), examine_item_menu::rate_action_use(), rate_food(), read(), avatar::read(), read_inventory_preset::read_inventory_preset(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), iuse::remoteveh(), repair_item_actor::repair_recipe_difficulty(), repaired_with(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::robotcontrol(), iexamine::safe(), iuse::seed(), mission::serialize(), player_morale::morale_point::serialize(), addiction::serialize(), vehicle::serialize(), iuse::sewage(), iuse::shavekit(), activity_handlers::shear_finish(), iuse::shocktonfa_off(), sight_dispersion(), simulate_burn(), iuse::siphon(), skim_book_msg(), iuse::sleep(), smoker_activate(), iuse::smoking(), activity_handlers::spellcasting_finish(), spoilage_sort_order(), stacks_with(), activity_handlers::start_fire_do_turn(), activity_handlers::start_fire_finish(), npc::start_read(), iuse::stimpack(), iuse::strong_antibiotic(), symbol(), iuse::talking_doll(), iuse::tazer(), iuse::teleport(), iuse::thorazine(), ranged::throw_item(), ranged::time_to_attack(), npc::time_to_read(), avatar::time_to_read(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), try_consume(), type_name(), typeId(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), update_clothing_mod_val(), charger_tile::update_internal(), iuse_transform::use(), countdown_actor::use(), consume_drug_iuse::use(), pick_lock_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), heal_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), install_bionic_actor::use(), avatar_funcs::use_item(), vehicle::use_monster_capture(), iuse::vaccine(), npc::value(), iuse::vibe(), volume(), iuse::vortex(), iuse::weak_antibiotic(), npc_ai::weapon_value(), iuse::weed_cake(), weight(), wheel_area(), vehicle_part::wheel_diameter(), vehicle_part::wheel_width(), npc::wield_better_weapon(), npc_ai::wielded_value(), npc::will_accept_from_player(), will_explode_in_fire(), and iuse::xanax().


The documentation for this class was generated from the following files: